How to XOR a byte output?

Stephen Hansen me+python at ixokai.io
Wed Apr 13 11:33:51 EDT 2016


On Wed, Apr 13, 2016, at 06:51 AM, durgadevi1 wrote:
> I would like to check with you whether using binascii.hexlify() to
> convert the series of bytes into alphabets and integers is correct.

To be clear, they already are integers.The \x notation is how you
naively represent a byte out of the printable range in ASCII. A byte is
a number from 0 to 255, which can also be thought of as 0x00 to 0xFF..
The 'printable range' is those bytes which represent normal characters
instead of control codes and such.

Computers like showing raw byte data in hex \x (which shouldn't be
confused with binascii.hexify) because then each byte concisely fills up
exactly 2 (well, 4, counting the \x) characters, instead of some bytes
being only one character (1), some being two (10), and some being three
(100).

You can see the integer value, consider:

>>> data = b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\\'
>>> print data[0]
36
>>> print data[10]
19
>>> list(data)
[36, 47, 47, 87, 63, 192, 130, 57, 162, 185, 19, 140, 213, 123, 92]

binascii is almost certainly not what you want: that converts arbitrary
bytes into an ASCII encoded string, at which point its no longer bytes
(and before you did something to it besides displaying it, you'd want to
decode it back to bytes again, probably).

--Stephen
m e @ i x o k a i . i o



More information about the Python-list mailing list