How to XOR two strings in Python
<p>H, I'm trying to XOR two strings (which should become hex first) in Python.
I know one way will work:</p>

<pre><code>def xor_two_str(str1, str2):
    return hex(int(str1,16) ^ int(str2,16))
</code></pre>

<p>But I tried sth like this:</p>

<pre><code>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")
</code></pre>

<p>This will return TypeError: ^ shouldn't be used between str, str.
I don't know why.</p>

<p>And also this function won't work:</p>

<pre><code>bcd = change_to_be_hex("12ef")
def increment_hex(hex_n):
   return hex_n + 1
result = increment_hex(bcd)
print result
</code></pre>

<p>The error message is : TypeError: cannot concatenate 'str' and 'int' objects
I feel this is so strange:(</p>

<p>Thank you!</p>