Modern Elliptic Curve Factorization, Part 2
April 27, 2010
The elliptic curve factorization algorithm is remarkably similar to Pollard’s p1 algorithm:
define p1 (n, B_{1}, B_{2})

1 
define ecf (n, B_{1}, B_{2}, C)

q = 2  2  Q_{x,z} ∈ C // random point 
for p ∈ π(2 … B_{1})  3  for p ∈ π(2 … B_{1}) 
a = ⌊log _{p} B_{1}⌋

4 
a = ⌊log _{p} B_{1}⌋

q = q^{pa} (mod n)

5  Q = p^{a} ⊗_{C} Q 
g = gcd (q, n)

6 
g = gcd (Q_{z}, n)

if (1 < g < n) return g  7  if (1 < g < n) return g 
for p ∈ π(B_{1} … B_{2})  8  for p ∈ π(B_{1} … B_{2}) 
q = q^{p} (mod n)

9  Q = p ⊗_{C} Q 
10 
g = g × Q_{z} (mod n)


g = gcd (q, n)

11 
g = gcd (g, n)

if (1 < g < n) return g  12  if (1 < g < n) return g 
return failure  13  return failure 
Lines 3 and 8 loop over the same lists of primes. Line 4 computes the same maximum exponent. Lines 6 and 7, and lines 11 and 12, compute the same greatest common divisor. And line 13 returns the same failure. The structures of the two algorithms are identical. Also, note that both algorithms use variables that retain their meaning from the first stage (lines 2 to 7) to the second stage (lines 8 to 12).
Lines 2, 5, 9 and 10 differ because p1 is based on modular arithmetic and ecf
is based on elliptic arithmetic (note that the ⊗_{C} operator, otimessubC, indicates elliptic multiplication on curve C). The most important difference is on the first line, where ecf
has an extra argument C indicating the choice of elliptic curve. If the p1 method fails, there is nothing to do, but if the ecf
method fails, you can try again with a different curve.
Use of Montgomery’s elliptic curve parameterization from the previous exercise is a huge benefit. Lenstra’s original algorithm, which is the first stage of the modern algorithm, required that we check the greatest common divisor at each step, looking for a failure of the elliptic arithmetic. With the modern algorithm, we compute the greatest common divisor only once, at the end, because Montgomery’s parameterization has the property that a failure of the elliptic arithmetic propagates through the calculation. And without inversions, Montgomery’s parameterization is also much faster to calculate. Brent’s parameterization of the randomlyselected curve is also important, as it guarantees that the order of the curve (the number of points) will be a multiple of 12, which has various good mathematical properties that we won’t enumerate here.
There is a simple coding trick that can speed up the second stage. Instead of multiplying each prime times Q, we iterate over i from B_{1} + 1 to B_{2}, adding 2Q at each step; when i is prime, the current Q can be accumulated into the running solution. Again, we defer the calculation of the greatest common divisor until the end of the iteration.
Your task is to write a function that performs elliptic curve factorization. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
Pages: 1 2
Two questions:
in line 6 of ecf, what is ‘q’
in line 11 of ecf, is that supposed to be g = gcd(*q*,n) like in the p1 function?
In line 6, q should read Qsubz (it’s the z parameter of the point Q). I’ll fix that.
In line 11, g is the g that is initialized on line 6 and accumulated on line 11.
Since no one posted the source code for this so here is mine.How ever running this algorithm and Lenstra implementation, Lenstra seems to be good.
Lenstra Implementation
http://mukeshiiitm.wordpress.com/2011/01/17/ellipticcurveprimefactorisation/
[...] is almost similar to previous example except using Montgomery curve rather than Lenstra curve. Programmingpraxis used Montgomery curve to find the prime factorisation. I personally feel that Lenstra algorithm [...]
A solution in Python, borrowing the functions from http://programmingpraxis.com/2010/04/23/modernellipticcurvefactorizationpart1/#comment1192: