gpt4 book ai didi

java - 破解哈希算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:29:57 27 4
gpt4 key购买 nike

<分区>

我正在尝试破解 Java 中的哈希算法:

    public static int encode(String file) {
int hash = 0;
file = file.toUpperCase();

for(int i = 0; i < file.length(); i++) {
hash = (hash * 61 + file.charAt(i)) - 32;
}
return hash;
}

这是我的尝试:

public static String decode(int hash) {
long realHash = (hash < 0 ? Integer.MAX_VALUE + Math.abs(hash) : hash);
ByteBuffer buffer = ByteBuffer.allocate(50);

while (realHash > 0) {
buffer.put((byte) ((realHash % 61) + 32));
realHash = (realHash - 32) / 61;
}
buffer.flip();
return new String(buffer.array()).trim();
}

我的解决方案似乎有严重的数据丢失,由于整数溢出,我认为我无法完全取消散列较长的文本数据。有什么建议吗?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com