Skip to content

Instantly share code, notes, and snippets.

@YarnSeemannsgarn
Last active August 29, 2015 14:20
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 YarnSeemannsgarn/0d7d0d3e71bed6726371 to your computer and use it in GitHub Desktop.
Save YarnSeemannsgarn/0d7d0d3e71bed6726371 to your computer and use it in GitHub Desktop.
# Hex xor by using strxor
def strxor(a, b): # xor two strings of different lengths
if len(a) > len(b):
return "".join([chr(ord(x) ^ ord(y)) for (x, y) in zip(a[:len(b)], b)])
else:
return "".join([chr(ord(x) ^ ord(y)) for (x, y) in zip(a, b[:len(a)])])
print "Hex 1: ",
a = raw_input().decode("hex")
print "Hex 2: ",
b = raw_input().decode("hex")
print strxor(a,b).encode("hex")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment