From 44b56a29426494cb7d52ab3f7731d31936b25868 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 21 Apr 2023 23:13:04 +0200 Subject: [PATCH] trash hash works now --- src/trash-hash.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/trash-hash.py b/src/trash-hash.py index bdf86ae..dab5fd4 100644 --- a/src/trash-hash.py +++ b/src/trash-hash.py @@ -33,22 +33,18 @@ def trash_hash(input: bytearray) -> bytearray: # print("block: %s" % block.hex()) # initilaize accumulator A_0 with the following constant values: - A_list = [DEFINED_INITIAL] * n + A = DEFINED_INITIAL # iterate over blocks for index, block in enumerate(blocks): if index == 0: pass - thing = bytes(by0 ^ by1 for by0, by1 in zip(A_list[index - 1], block)) - A_list[index] = bytearray(thing) - print("final thing: %s" % A_list[index]) + thing = bytes(by0 ^ by1 for by0, by1 in zip(A, block)) + A = bytearray(thing) - A = bytearray(1) - A.pop() + return A - return A.join(A_list) - -def main(): +def use(): some_bytes = bytearray(b'AAAA'); print("hashed: %s" % some_bytes.hex()) print('='*80) @@ -56,5 +52,13 @@ def main(): print('='*80) print("hashed: %s" % hashed.hex()) +def test_collision(a: bytearray, b: bytearray) -> bool: + return trash_hash(a) == trash_hash(b) + +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())) + if __name__ == "__main__": main()