[pycrypto] Python 3.x vs. Python 2.1 - stay of execution

Thorsten Behrens sbehrens at gmx.li
Mon Dec 27 23:39:59 CST 2010


Writing this stuff out helps me think about it. I have a solution. When, 
or if, the 3.x port is successful, the fate of 2.1 can be decided.

For now, I have created two files: Util/py21floordiv.py and 
Util/floordiv.py. In Util/number.py, I then include based on version:

if sys.version[0:3] == "2.1":
     from Crypto.Util.py21floordiv import *
else:
     from Crypto.Util.floordiv import *

The offending code snippet

     if GCD (e, (X-1)/2) != 1:

becomes

     if GCD (e, floordiv((X-1),2)) != 1:

This works on Python 2.1, 2.7 and 3.1

Thorsten

On 12/28/2010 12:16 AM, Thorsten Behrens wrote:
> I've run into a bit of a snag. The / operator in 2.x returns an int, and
> in 3.x it can return a float. This causes an infinite loop in
> numbers.py. I can solve it with //, which is supported from 2.2 on, but
> not in 2.1.



More information about the pycrypto mailing list