[Python-ideas] Bitwise operations on bytes class
Nathaniel McCallum
npmccallum at redhat.com
Tue Jun 17 15:24:57 CEST 2014
On Tue, 2014-06-17 at 09:53 +1200, Greg Ewing wrote:
> 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.
+1
More information about the Python-ideas
mailing list