CRC32反向哈希解密函数输出与输入哈希不匹配的修复求助(哈希e8b7be43对应明文'a')
CRC32反向哈希解密函数输出与输入哈希不匹配的修复求助(哈希e8b7be43对应明文'a')
我现在正尝试把一个哈希值反向还原成对应的字节序列,下面是我写的解密函数:
def decrypt(hash, size): bytes = bin(int(hash, 16)).replace("0b", "").zfill(32) bytes = flip(reverse(int(bytes, 2), 32), 33) div = "100000100110000010001110110110111" bytes = bytes.zfill(size*8) div = div.zfill(size*8) res = "" print(bytes + " - DIV") print(div + " - POLY") while div[0] != "1": res = "" for b in range(len(bytes)): if div[b] == bytes[b]: res = res + "0" else: res = res + "1" bytes = bin(int(res, 2) << 1).replace("0b", "").zfill(size*8) div = bin(int(div, 2) << 1).replace("0b", "").zfill(size*8) print(bytes + " - DIV") print(div + " - POLY") print(bytes) bytes = flip(bytes[0:8], 8) + flip(bytes[8:16], 8) + flip(bytes[16:24], 8) + flip(bytes[24:32], 8) + bytes[32:len(bytes)] bytes = bytes[0:len(bytes)-32] bytes = [int(reverse(int(bytes[(c*8):(c+1)*8], 2), 8), 2) for c in range(int(len(bytes)/8))] print(hex(zlib.crc32(bytearray(bytes)))) return bytes print(decrypt(sys.argv[1], int(sys.argv[2])+4))
对应的运行输出如下:
>>>python encrypt.py a 40 0xe8b7be43 [97] >>>python decrypt.py e8b7be43 1 0000000000111101100000100001001011101000 - DIV 0000000100000100110000010001110110110111 - POLY 0000001001110010100001100001111010111110 - DIV 0000001000001001100000100011101101101110 - POLY 0000000011110110000010000100101110100000 - DIV 0000010000010011000001000111011011011100 - POLY 0000100111001010000110000111101011111000 - DIV 0000100000100110000010001110110110111000 - POLY 0000001111011000001000010010111010000000 - DIV 0010000010011000001000111011011011100000 - POLY 0010011100101000011000011110101111100000 - DIV 0010000010011000001000111011011011100000 - POLY 0000111101100000100001001011101000000000 - DIV 0100000100110000010001110110110111000000 - POLY 1001110010100001100001111010111110000000 - DIV 1000001001100000100011101101101110000000 - POLY 1001110010100001100001111010111110000000 0xa0058808 [198]
现在遇到的问题是:解密函数生成的字节数组的CRC32哈希值和我输入的e8b7be43完全不匹配,请问我该怎么修复这个问题?
备注:内容来源于stack exchange,提问作者Nguyen Tran
相关产品推荐
相关产品推荐

