Skip to content

Instantly share code, notes, and snippets.

@MayerDaniel
Created January 5, 2021 00:49
Show Gist options
  • Save MayerDaniel/3a01aae53d6d48a5722cddd715b855ff to your computer and use it in GitHub Desktop.
Save MayerDaniel/3a01aae53d6d48a5722cddd715b855ff to your computer and use it in GitHub Desktop.
python xor
#python2 or 3
def xor_two_str(a,b):
return ''.join([chr(ord(a[i%len(a)]) ^ ord(b[i%(len(b))])) for i in range(max(len(a), len(b)))])
#python3 bytes - add cycle() if the two byte strings are not the same length
def byte_xor(ba1, ba2):
return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment