I am trying to reverse a hash into a sequence of bytes. The function is shown below. 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 == bytes: 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)) And here is the output. >>>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] The issue here is that the hash of the bytearray that the "decrypt" function generates does not match the input hash e8b7be43. How do I fix this? Continue reading...