Created
January 5, 2021 00:49
-
-
Save MayerDaniel/3a01aae53d6d48a5722cddd715b855ff to your computer and use it in GitHub Desktop.
python xor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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