H, I'm trying to XOR two strings (which should become hex first) in Python. I know one way will work:
def xor_two_str(str1, str2):
return hex(int(str1,16) ^ int(str2,16))
But I tried sth like this:
def change_to_be_hex(str):
return hex(int(str,base=16))
def xor_two_str(str1,str2):
a = change_to_be_hex(str1)
b = change_to_be_hex(str2)
return hex(a ^ b)
print xor_two_str("12ef","abcd")
This will return TypeError: ^ shouldn't be used between str, str. I don't know why.
And also this function won't work:
bcd = change_to_be_hex("12ef")
def increment_hex(hex_n):
return hex_n + 1
result = increment_hex(bcd)
print result
The error message is : TypeError: cannot concatenate 'str' and 'int' objects I feel this is so strange:(
Thank you!
^
on strings. What's your question then?