Here’s a simple function you can use to XOR decode data in Python:
def xor(input: bytes, key: bytes) -> bytes:
return bytes(a ^ b for a, b in zip(input, itertools.cycle(key)))
It uses itertools.cycle
rather than manually computing the rolling index into the key with something like key[i % len(key)]
.