trying to find collisions

This commit is contained in:
Christoph J. Scherr 2023-04-21 23:48:36 +02:00
parent 44b56a2942
commit 00d42b28db
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
1 changed files with 20 additions and 5 deletions

View File

@ -8,15 +8,15 @@ import random
DEFINED_INITIAL = bytearray(b'\xa5\xa5\xa5\xa5\x5a\x5a\x5a\x55\x55\x55\xaa\xaa\xaa') DEFINED_INITIAL = bytearray(b'\xa5\xa5\xa5\xa5\x5a\x5a\x5a\x55\x55\x55\xaa\xaa\xaa')
def trash_hash(input: bytearray) -> bytearray: 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 # extend with 0xff if length is not multiple of 16
while len(input) % 16 != 0: while len(input) % 16 != 0:
input.append(0xff) input.append(0xff)
# set n # set n
n: int = math.ceil(len(input)/16) n: int = math.ceil(len(input)/16)
print("len is %s" % len(input)) #print("len is %s" % len(input))
print("n is %s" % n) #print("n is %s" % n)
# cut input into blocks with size 16 # cut input into blocks with size 16
blocks = [bytearray(16)] * n # initializes with 0x00s blocks = [bytearray(16)] * n # initializes with 0x00s
@ -57,8 +57,23 @@ def test_collision(a: bytearray, b: bytearray) -> bool:
def main(): def main():
payload_a = bytearray(b"AAAA") payload_a = bytearray(b"AAAA")
payload_b = bytearray(random.randbytes(122)) # works, but is too cheap
print("a: %s\tb: %s" % (trash_hash(payload_a).hex(), trash_hash(payload_b).hex())) #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__": if __name__ == "__main__":
main() main()