how can we XOR hex numbers in python eg. I want to xor 'ABCD' to '12EF'. answer should be B922.
i used below code but it is returning garbage value
def strxor(a, b): # xor two strings of different lengths
if len(a) > len(b):
return "".join(["%s" % (ord(x) ^ ord(y)) for (x, y) in zip(a[:len(b)], b)])
else:
return "".join(["%s" % (ord(x) ^ ord(y)) for (x, y) in zip(a, b[:len(a)])])
key ='12ef'
m1='abcd'
print strxor(key,m1)
question from:https://stackoverflow.com/questions/11119632/bitwise-xor-of-hex-numbers-in-python