Python CRC32 反向哈希 e8b7be43 到字符串“a”

问题描述 投票:0回答:1

我正在尝试将哈希反转为字节序列。功能如下所示。

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
0001000001001100000100011101101101110000 - POLY
0010011100101000011000011110101111100000 - DIV
0010000010011000001000111011011011100000 - POLY
0000111101100000100001001011101000000000 - DIV
0100000100110000010001110110110111000000 - POLY
1001110010100001100001111010111110000000 - DIV
1000001001100000100011101101101110000000 - POLY
1001110010100001100001111010111110000000
0xa0058808
[198]

这里的问题是“解密”函数生成的字节数组的哈希与输入哈希 e8b7be43 不匹配。我该如何解决这个问题?

python crc32
1个回答
0
投票

请理解“散列”与“加密”有很大不同。 是的,一个可以 构建 来自安全哈希的密码。 但这不是这里发生的情况,crc32 绝不是一个 安全哈希, 更何况 32 位的安全参数很容易被破解。

我该如何解决这个问题?

阅读加密工程。 或类似的参考资料,并重新考虑解决业务问题的方法。 您希望将相关的加密原语应用到它上面。

© www.soinside.com 2019 - 2024. All rights reserved.