Blowfish in Python?
Markus Stenberg
mstenber at cc.Helsinki.FI
Tue Feb 29 09:42:56 EST 2000
"Tim Peters" <tim_one at email.msn.com> writes:
> [Markus Stenberg]
> > ...
> > speed was horrendous. >
> > I think the main reason was the fact that I had to use _long ints_ for
> > calculations, as the normal ints are signed, and apparently the bitwise
> > operators do not work as advertised when bit32 is set (=number is
> > negative). Or that's my theory anyway - my implementation worked with
> > long's and did not work with ints.
> Try to whittle this down. Negative ints are nothing special to the bitwise
> ops, so if they "don't work as advertised" it would be a (very surprising!)
> bug in the implementation. For example, here's the implementation of int &:
<snip>
> They're all like that -- they can't screw up unless C screws up.
Hmm.. As far as I'm concerned, shifts for example do screw up.
i.e.
0xffffffff >> 30
[64bit Python: 3]
[32bit Python: -1]
As far as I'm concerned, that should _not_ happen. Or maybe it's just me.
> And are routinely highly optimized too. Once you get "&" to work <wink>,
> one machine instruction in C is going to turn into a couple of function
> calls in Python.
Yes, & works. + does not (that's obvious), but shifts not working was
disappointment (made implementation of say, +, somewhat painful and thus
inefficient).
> > my Python-with-longs implementation was kilobytes/second, to be precise,
> > 2-10k/s depending on the machine.
> Using ints will get you the biggest bang for the buck at this point, but
> it's never going to be *fast* in pure Python 1.5.2.
As a matter of fact, my "function for >> and +" approach was actually
_slower_ than just using long's and (when needed) rounding them down.
Problem, apparently: each "most simple cycle" in Blowfish code involves 3
shifts to right, one +, and several array lookups.
Guess I could gain lot of speed by putting the stuff within One Huge
Function(r), but I intended code to be somewhat readable as well.. *sigh*
> not-implying-it-will-be-faster-in-later-versions-either<wink>-ly y'rs - tim
-Markus
--
Finger mstenber at sirppi.helsinki.fi for my PGP public key:
pub 1024/5DAC7D21 1994/04/20 Markus Stenberg <fingon at iki.fi>
Key fingerprint = 25 BA 5B 57 F1 77 0C F0 2A D0 E6 3A 2E 81 6F D3
More information about the Python-list
mailing list