2009-07-17, 02:43 AM
Python does not allow strings or chars to be xor'd. You have to change them from strings to bytes, xor them, then convert back.
Code:
>>> MyChar = "P"
>>> MyChar ^ 0xFF
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
MyChar ^ 0xFF
TypeError: unsupported operand type(s) for ^: 'str' and 'int'
>>> import struct
>>> MyChar = struct.unpack('b', MyChar)[0] #Essentially atoi(). 'b' means "signed byte"
>>> print(MyChar)
80
>>> MyChar ^ 0xFF
175