Reputation: 35
I am reading a block of bytes from a binary file using file.read(block_size). The variable that these bytes go into is typed <class 'bytes'>.
I need to XOR each byte in the stream with single byte value expressed in Hex, e.g. \x0A.
What is the operator in Python for doing this?
Upvotes: 0
Views: 205
Reputation: 1584
Python's bitwise-XOR operator is ^
>>> 15^8
7
edit: The XOR operator works with hex numbers as well:
>>> 0xA^8
2
Upvotes: 0