This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cowlicks
Recipients Ramchandra Apte, abarnert, christian.heimes, cowlicks, georg.brandl, gvanrossum, josh.r, martin.panter, pitrou, rhettinger, serhiy.storchaka, socketpair, terry.reedy, vstinner
Date 2016-01-10.14:48:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1452437327.25.0.380801929125.issue19251@psf.upfronthosting.co.za>
In-reply-to
Content
I've attached a diff that adds ^, |, and & to bytes and bytearray object on the master branch (err the analogous hg thing).

It also includes a test file which definitely is in the wrong place, but demonstrates what is working.

Personally this came up while I was playing with toy crypto problems. I expected to already be part of the language, but it wasn't. I think this is a natural expectation. I don't think it is obvious to newer python users that they need to cast bytes to ints to do bitwise operations on them.

And I do not understand how bitwise operations work on arbitrary precision integers. So perhaps it is not as simple of a concept as "bytes xor bytes".

Some folks have suggested using NumPy, but that is a very heavy dependency, and not useful outside of cpython.

I searched for code this would clean up in the wild. It was easy to find.

This would also catch bugs when bytes objects are different lengths, but there is no check. Like this code I found 

# XOR each byte of the roundKey with the state table
def addRoundKey(state, roundKey):
    for i in range(len(state)):
        state[i] = state[i] ^ roundKey[i]

p.s. this is my first cpython issue/patch please let me know if I'm doing something wrong.
History
Date User Action Args
2016-01-10 14:48:47cowlickssetrecipients: + cowlicks, gvanrossum, georg.brandl, rhettinger, terry.reedy, pitrou, vstinner, christian.heimes, socketpair, Ramchandra Apte, martin.panter, serhiy.storchaka, abarnert, josh.r
2016-01-10 14:48:47cowlickssetmessageid: <1452437327.25.0.380801929125.issue19251@psf.upfronthosting.co.za>
2016-01-10 14:48:47cowlickslinkissue19251 messages
2016-01-10 14:48:46cowlickscreate