[pycrypto] Python 3.x vs. Python 2.1 - prep the axe
Glenn Linderman
v+python at g.nevcal.com
Mon Dec 27 23:27:02 CST 2010
On 12/27/2010 9:16 PM, Thorsten Behrens wrote:
> If you can think of a reasonably clean way of handling the "/" vs. "//"
> issue - or if anyone else can - please share.
>
> Barring that, I think my message is: If Python 3.x is to be supported
> without code duplication, Python 2.1 support may have to go.
>
> Yours
>
> Thorsten
>
> # if e is given make sure that e and X-1 are coprime
> # this is not necessarily a strong prime criterion but useful when
> # creating them for RSA where the p-1 and q-1 should be coprime to
> # the public exponent e
> if e and is_possible_prime:
> if e& 1:
> if GCD (e, X-1) != 1:
> is_possible_prime = 0
> else:
> # Python 2.1 does not understand //, and 3.x returns a
> float on /
> # Infinite loop, wheee!!!
> if GCD (e, (X-1)//2) != 1:
> is_possible_prime = 0
Ugly hack, not sure if it is worthwhile.
utils.py:
def slashslash( a, b ):
return a / b
utilsnew.py:
def slashslash( a, b ):
return a // b
in numbers.py:
if sys.version_info[ 0 ] <= 2 and sys.version_info[ 1 ] <= 1:
import utils
else:
import utilsnew as utils
...
if GCD ( e, utils.slashslash(X-1,2) != 1:
# Not sure if 2.1 will ignore "as" if not executed? If not, then you
play the setup.py with a tiny file.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.dlitz.net/pipermail/pycrypto/attachments/20101227/aa13763d/attachment.htm
More information about the pycrypto
mailing list