diff --git a/src/trash-hash.py b/src/trash-hash.py index dab5fd4..e327a34 100644 --- a/src/trash-hash.py +++ b/src/trash-hash.py @@ -8,15 +8,15 @@ import random DEFINED_INITIAL = bytearray(b'\xa5\xa5\xa5\xa5\x5a\x5a\x5a\x55\x55\x55\xaa\xaa\xaa') def trash_hash(input: bytearray) -> bytearray: - print("original len is %s" % len(input)) + #print("original len is %s" % len(input)) # extend with 0xff if length is not multiple of 16 while len(input) % 16 != 0: input.append(0xff) # set n n: int = math.ceil(len(input)/16) - print("len is %s" % len(input)) - print("n is %s" % n) + #print("len is %s" % len(input)) + #print("n is %s" % n) # cut input into blocks with size 16 blocks = [bytearray(16)] * n # initializes with 0x00s @@ -57,8 +57,23 @@ def test_collision(a: bytearray, b: bytearray) -> bool: def main(): payload_a = bytearray(b"AAAA") - payload_b = bytearray(random.randbytes(122)) - print("a: %s\tb: %s" % (trash_hash(payload_a).hex(), trash_hash(payload_b).hex())) + # works, but is too cheap + #payload_b = bytearray(b"AAAA\xff\xff") + payload_b = bytearray(b'\xb2\xef\x82t<~<\xbe\x8d\xca\xe2\t\xdc7E\x10') + print("a: %s\nb: %s" % (trash_hash(payload_a).hex(), trash_hash(payload_b).hex())) + print("identical: %s" % test_collision(payload_a, payload_b)) + +def bruteForce() -> bool: + payload_a = bytearray(b"AAAA") + foundCollision = False + while not foundCollision: + current = bytearray(random.randbytes(16)) + foundCollision = test_collision(payload_a, current) + if random.randint(1, 65535) % 65535 == 0: + print(current) + print("found one!") + print(current) + return True if __name__ == "__main__": main()