[Python-ideas] Bitwise operations on bytes class

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Jun 16 23:53:03 CEST 2014


Nathaniel McCallum wrote:
> In all the surrounding code, you are dealing with bytes *as* bytes.
> Converting into alternate types breaks up the readability of the
> algorithm. And given the security requirements of such algorithms,
> readability is extremely important.

Not to mention needlessly inefficient.

There's also the issue that you are usually dealing
with a specific number of bits. When you convert to
an int, you lose any notion of it having a size, so
you have to keep track of that separately, and take
its effect on the bitwise operations into account
manually.

E.g. the bitwise complement of an N-bit string is
another N-bit string. But the bitwise complement of
a positive int is a bit string with an infinite
number of leading 1 bits, which you have to mask
off. The bitwise complement of a bytes object, on
the other hand, would be another bytes object of
the same size.

-- 
Greg


More information about the Python-ideas mailing list