Skip to content

Instantly share code, notes, and snippets.

@saxbophone
Created February 22, 2015 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saxbophone/5c1bacc1960a8eda1b88 to your computer and use it in GitHub Desktop.
Save saxbophone/5c1bacc1960a8eda1b88 to your computer and use it in GitHub Desktop.
Python Recursive XOR
from operator import xor as _xor_
def xor(a, b):
try:
if len(a) is not 1 and len(b) is not 1:
result = []
for i in range(0,len(a)):
result.append(xor(a[i], b[i]))
return result
else:
if isinstance(a, str):
a = ord(a)
if isinstance(b, str):
b = ord(b)
return _xor_(a, b)
except TypeError:
return _xor_(a, b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment