def MD(message, H): for block in blocks(message): H = C(block, H) return H
def MD(message): H = 0xde98 for block in blocks(pad(message)): H = C(block, H) return H
if short_hash in long_hashes: long_blocks = long_prefix + long_hashes[short_hash] assert len(long_blocks) == block_size * num_blocks assert MD(long_blocks, H) == short_hash return (short_block, long_blocks, short_hash) with open('paper-preimages.pdf', 'rb') as fp: data = fp.read() data = pad(data) intermediates = [] H = 0x3fe4 for block in blocks(data): intermediates.append(H) H = C(block, H) data_hash = H expandable = [] H = 0x3fe4 for i in range(16): (m1, m2, H) = find_collision(16 - i, H) expandable.append((i, m1, m2, H)) # This sometimes fails. If it does, just run it again. assert H in intermediates index = intermediates.index(H) assert index > len(expandable)
len_leaves, roots, glue_num, leaves, all_nodes = best_root # Our length: glue_num blocks, 64 for the message, one glue block end_block = b'\0' + (glue_num * 16 + 64 + 16).to_bytes(8, 'big') + b'\0' * 7 end_hash = roots[0][2] print('Root block hash', end_hash) end_hash = C(end_block, end_hash) print('Prediction with hash: %d' % end_hash) message = b'A Tesla will be able to drive itself across the country in 2018.' assert len(message) == 64 H = 0xde98 for block in blocks(message): H = C(block, H) print('H of message', H) leaf_index = {} for leaf in leaves: leaf_index[leaf[0]] = leaf # Find a block that map from H to anything in leaf_index while True: block = os.urandom(16) glued_h = C(block, H) if glued_h in leaf_index: break