summaryrefslogtreecommitdiff
path: root/pipermail/pycrypto/2010q4/000351.html
blob: d7e14264d0faf2f315cb51c3ebddc3fd2f908c6c (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
 <HEAD>
   <TITLE> [pycrypto] Python 3.x vs. Python 2.1 - prep the axe
   </TITLE>
   <LINK REL="Index" HREF="index.html" >
   <LINK REL="made" HREF="mailto:pycrypto%40lists.dlitz.net?Subject=%5Bpycrypto%5D%20Python%203.x%20vs.%20Python%202.1%20-%20prep%20the%20axe&In-Reply-To=4D1972A2.4080305%40gmx.li">
   <META NAME="robots" CONTENT="index,nofollow">
   <META http-equiv="Content-Type" content="text/html; charset=us-ascii">
   <LINK REL="Previous"  HREF="000347.html">
   <LINK REL="Next"  HREF="000352.html">
 </HEAD>
 <BODY BGCOLOR="#ffffff">
   <H1>[pycrypto] Python 3.x vs. Python 2.1 - prep the axe</H1>
    <B>don at amberfisharts.com</B> 
    <A HREF="mailto:pycrypto%40lists.dlitz.net?Subject=%5Bpycrypto%5D%20Python%203.x%20vs.%20Python%202.1%20-%20prep%20the%20axe&In-Reply-To=4D1972A2.4080305%40gmx.li"
       TITLE="[pycrypto] Python 3.x vs. Python 2.1 - prep the axe">don at amberfisharts.com
       </A><BR>
    <I>Wed Dec 29 11:21:57 CST 2010</I>
    <P><UL>
        <LI>Previous message: <A HREF="000347.html">[pycrypto] Python 3.x vs. Python 2.1 - prep the axe
</A></li>
        <LI>Next message: <A HREF="000352.html">[pycrypto] Python 3.x vs. Python 2.1 - prep the axe
</A></li>
         <LI> <B>Messages sorted by:</B> 
              <a href="date.html#351">[ date ]</a>
              <a href="thread.html#351">[ thread ]</a>
              <a href="subject.html#351">[ subject ]</a>
              <a href="author.html#351">[ author ]</a>
         </LI>
       </UL>
    <HR>  
<!--beginarticle-->
<PRE> Hi

 If the only occurrence of this problem is with divisions by 2 then 
 couldn't you use a&gt;&gt;1 instead?

 cheers and great to see some more effort and progress on py3k support.
 //Lorenz
 
 On Tue, 28 Dec 2010 00:16:18 -0500, Thorsten Behrens &lt;<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">sbehrens at gmx.li</A>&gt; 
 wrote:
&gt;<i> On 12/23/2010 11:51 PM, Thorsten Behrens wrote:
</I>&gt;&gt;<i> On 12/23/2010 9:18 PM, Dwayne C. Litzenberger wrote:
</I>&gt;&gt;&gt;<i> Also, down the road, I could be convinced to drop Python 2.1 
</I>&gt;&gt;&gt;<i> support, if I
</I>&gt;&gt;&gt;<i> had some concrete examples showing that the result would be 
</I>&gt;&gt;&gt;<i> substantially
</I>&gt;&gt;&gt;<i> less error-prone, easier to maintain, etc.
</I>&gt;&gt;<i> So far, it doesn't look like that's needed. dict.has_key() cannot be
</I>&gt;&gt;<i> replaced with &quot;in&quot; for 2.1, but 2to3 seems to handle it fine.
</I>&gt;<i>
</I>&gt;<i> I've run into a bit of a snag. The / operator in 2.x returns an int, 
</I>&gt;<i> and
</I>&gt;<i> in 3.x it can return a float. This causes an infinite loop in
</I>&gt;<i> numbers.py. I can solve it with //, which is supported from 2.2 on, 
</I>&gt;<i> but
</I>&gt;<i> not in 2.1.
</I>&gt;<i>
</I>&gt;<i> I've pasted the offending code snippet from numbers.py below, in the
</I>&gt;<i> form that doesn't cause an infinite loop in 3.x.
</I>&gt;<i>
</I>&gt;<i> I'm at a bit of a loss here. int(math.floor(a/b)) is not an option 
</I>&gt;<i> due
</I>&gt;<i> to the size of the operands - it actually fails on 2.1, and gives
</I>&gt;<i> incorrect results on 3.x. That means I am stuck with //.
</I>&gt;<i>
</I>&gt;<i> I don't know how to &quot;import something&quot; and have &quot;something&quot; show up 
</I>&gt;<i> in
</I>&gt;<i> the namespace above. I don't think it works that way, unlike a C
</I>&gt;<i> #include. That means I can't just bring the right function in 
</I>&gt;<i> depending
</I>&gt;<i> on version. And even if I could, 2.1 doesn't have the &quot;as&quot; keyword, 
</I>&gt;<i> so
</I>&gt;<i> it would never show up with the right numbers.getStrongPrime name
</I>&gt;<i> anyway, even _if_ such nested namespace manipulations were supported.
</I>&gt;<i> Which I don't think they are.
</I>&gt;<i>
</I>&gt;<i> I can't just &quot;if sys.version&quot; the offending code snippet, either: 2.1
</I>&gt;<i> will still complain that // is a syntax error.
</I>&gt;<i>
</I>&gt;<i> We could duplicate the code and have setup.py bring in a 
</I>&gt;<i> special-cased
</I>&gt;<i> numbers.py for 2.1. I'm not sure how to do that with setup.py, but
</I>&gt;<i> there's got to be a way, even if it's just renaming files as needed.
</I>&gt;<i>
</I>&gt;<i> But that means duplicating an entire module, which is ugly. And I 
</I>&gt;<i> can't
</I>&gt;<i> guarantee that this is the only occurrence of / that causes issues. 
</I>&gt;<i> In
</I>&gt;<i> fact, I'd wager some beer that it likely isn't.
</I>&gt;<i>
</I>&gt;<i> If you can think of a reasonably clean way of handling the &quot;/&quot; vs. 
</I>&gt;<i> &quot;//&quot;
</I>&gt;<i> issue - or if anyone else can - please share.
</I>&gt;<i>
</I>&gt;<i> Barring that, I think my message is: If Python 3.x is to be supported
</I>&gt;<i> without code duplication, Python 2.1 support may have to go.
</I>&gt;<i>
</I>&gt;<i> Yours
</I>&gt;<i>
</I>&gt;<i> Thorsten
</I>&gt;<i>
</I>&gt;<i>          # if e is given make sure that e and X-1 are coprime
</I>&gt;<i>          # this is not necessarily a strong prime criterion but 
</I>&gt;<i> useful when
</I>&gt;<i>          # creating them for RSA where the p-1 and q-1 should be 
</I>&gt;<i> coprime to
</I>&gt;<i>          # the public exponent e
</I>&gt;<i>          if e and is_possible_prime:
</I>&gt;<i>              if e &amp; 1:
</I>&gt;<i>                  if GCD (e, X-1) != 1:
</I>&gt;<i>                      is_possible_prime = 0
</I>&gt;<i>              else:
</I>&gt;<i>                  # Python 2.1 does not understand //, and 3.x returns 
</I>&gt;<i> a
</I>&gt;<i> float on /
</I>&gt;<i>                  # Infinite loop, wheee!!!
</I>&gt;<i>                  if GCD (e, (X-1)//2) != 1:
</I>&gt;<i>                      is_possible_prime = 0
</I>&gt;<i> _______________________________________________
</I>&gt;<i> pycrypto mailing list
</I>&gt;<i> <A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto at lists.dlitz.net</A>
</I>&gt;<i> <A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</A>
</I>
</PRE>







<!--endarticle-->
    <HR>
    <P><UL>
        <!--threads-->
	<LI>Previous message: <A HREF="000347.html">[pycrypto] Python 3.x vs. Python 2.1 - prep the axe
</A></li>
	<LI>Next message: <A HREF="000352.html">[pycrypto] Python 3.x vs. Python 2.1 - prep the axe
</A></li>
         <LI> <B>Messages sorted by:</B> 
              <a href="date.html#351">[ date ]</a>
              <a href="thread.html#351">[ thread ]</a>
              <a href="subject.html#351">[ subject ]</a>
              <a href="author.html#351">[ author ]</a>
         </LI>
       </UL>

<hr>
<a href="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">More information about the pycrypto
mailing list</a><br>
</body></html>