Blowfish in Python?

Richard Brodie R.Brodie at rl.ac.uk
Wed Mar 1 05:43:42 EST 2000


"Michael Zawrotny" <zawrotny at gecko.sb.fsu.edu> wrote in message
news:slrn8bnveq.1jn.zawrotny at gecko.sb.fsu.edu...
> Markus,
>
> On 29 Feb 2000, Markus Stenberg <mstenber at cc.Helsinki.FI> wrote:
> > Hmm.. As far as I'm concerned, shifts for example do screw up.

> > 0xffffffff >> 30
> >
> > [64bit Python: 3]
> > [32bit Python: -1]
> >
> > As far as I'm concerned, that should _not_ happen. Or maybe it's just me.
>
> In an ideal world, perhaps not.  It does seem to be one of those places
> that the standard allows implementors some leeway in behavior.  K&R 2nd
> Ed. p. 49 says:

Yes but I hope we're not into saying - if 'C' does it it must be right ;)
Java, for example, has two right shift operators, so the behaviour is
well defined. The Python documentation is fairly clear that sign
extension is required; so the C implementation, at least, looks broken
in that it relies on undefined behaviour.

When I try with ints and long ints, I get:

0xffffffff >> 30 = -1
0xffffffffL >> 30 = 3L

Which is perhaps unexpected but having -1 >> 30 different from
-1L >> 30 is worse, IMHO. I think the heart of the problem is that
0xffffffff != 0xffffffffL. Presumably the literal 0xffffffff isn't -1 on a
64bit Python either.









More information about the Python-list mailing list