diff --git a/__pycache__/xorCorrelator.cpython-38.pyc b/__pycache__/xorCorrelator.cpython-38.pyc index 20f9312..4e7332a 100644 Binary files a/__pycache__/xorCorrelator.cpython-38.pyc and b/__pycache__/xorCorrelator.cpython-38.pyc differ diff --git a/xorCorrelator.py b/xorCorrelator.py index 0270bed..b5b441f 100644 --- a/xorCorrelator.py +++ b/xorCorrelator.py @@ -1,4 +1,5 @@ import secrets +import hashlib def xor(a: bytes, b: bytes): if len(a)!=len(b): @@ -21,7 +22,7 @@ def cbcXor(blocks, key: bytes, iv: bytes = None, BS=16): res.append(enc) return res -def decCbcXor(blocks, key: bytes, iv: bytes = None, BS=16): +def decCbcXor(blocks, key: bytes, iv: bytes = None, BS: int = 16): if len(key)!=BS: raise Exception("Bad key len") if not iv: @@ -37,5 +38,25 @@ def decCbcXor(blocks, key: bytes, iv: bytes = None, BS=16): res.append(enc) return res -def randBlocks(num: int = 64): +def randBlocks(num: int = 64, BS: int = 16): return [secrets.token_bytes(16) for i in range(num)] + +def hashsum(blocks): + return hashlib.sha3_256("".join(blocks)).digest() + +def buildCollisionMatrix(blocks): + mat = [] + for b in range(0,len(blocks)-1): + line = [] + for c in range(b+1,len(blocks)): + block = blocks[b] + compr = blocks[c] + + collLen = 0 + for d in range(len(block)): + if block[d]!=compr[d]: + break + collLen+=1 + line.append(collLen) + mat.append(line) + return mat