1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
<tt>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><br>
<html><br>
<head><br>
<meta content="text/html; charset=ISO-8859-1"<br>
http-equiv="Content-Type"><br>
</head><br>
<body text="#330033" bgcolor="#ffffff"><br>
On 12/27/2010 9:16 PM, Thorsten Behrens wrote:<br><br>
<blockquote cite="mid:4D1972A2.4080305@gmx.li" type="cite"><br>
<pre wrap="">If you can think of a reasonably clean way of handling the "/" vs. "//" <br>
issue - or if anyone else can - please share.<br>
<br>
Barring that, I think my message is: If Python 3.x is to be supported <br>
without code duplication, Python 2.1 support may have to go.<br>
<br>
Yours<br>
<br>
Thorsten<br>
<br>
# if e is given make sure that e and X-1 are coprime<br>
# this is not necessarily a strong prime criterion but useful when<br>
# creating them for RSA where the p-1 and q-1 should be coprime to<br>
# the public exponent e<br>
if e and is_possible_prime:<br>
if e &amp; 1:<br>
if GCD (e, X-1) != 1:<br>
is_possible_prime = 0<br>
else:<br>
# Python 2.1 does not understand //, and 3.x returns a <br>
float on /<br>
# Infinite loop, wheee!!!<br>
if GCD (e, (X-1)//2) != 1:<br>
is_possible_prime = 0<br>
</pre><br>
</blockquote><br>
<br><br>
Ugly hack, not sure if it is worthwhile.<br><br>
<br><br>
utils.py:<br><br>
def slashslash( a, b ):<br><br>
&nbsp;&nbsp;&nbsp; return a / b<br><br>
<br><br>
utilsnew.py:<br><br>
def slashslash( a, b ):<br><br>
&nbsp;&nbsp;&nbsp; return a // b<br><br>
<br><br>
in numbers.py:<br><br>
<br><br>
if sys.version_info[ 0 ] &lt;= 2&nbsp; and sys.version_info[ 1 ] &lt;= 1:<br><br>
&nbsp;&nbsp;&nbsp; import utils<br><br>
else:<br><br>
&nbsp;&nbsp;&nbsp; import utilsnew as utils<br><br>
...<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if GCD ( e,<br>
utils.slashslash(X-1,2) != 1:<br><br>
<br><br>
# Not sure if 2.1 will ignore "as" if not executed?&nbsp; If not, then<br>
you play the setup.py with a tiny file.<br><br>
</body><br>
</html><br>
</tt>
|