## Modern Elliptic Curve Factorization, Part 2

### April 27, 2010

Here is our version, which relies on Montgomery’s elliptic arithmetic from the previous exercise:

`(define (ec-factor N B1 B2 S)`

(let-values (((An Ad Q) (curve12 N S)))

(let stage1 ((p 2) (Q Q))

(if (< p B1)

(stage1 (next-prime p) (multiply (expt p (ilog p B1)) Q An Ad N))

(let ((g (gcd (cdr Q) n))) (if (< 1 g n) g

(let ((QQ (double Q An Ad N))

(R (multiply (- B1 1) q An Ad n))

(T (multiply (+ B1 1) q An Ad n)))

(let stage2 ((p (next-prime B1)) (g g) (k (+ B1 1)) (R R) (T T))

(cond ((< B2 p) (let ((g (gcd g n))) (if (< 1 g n) g #f)))

((= k p) (stage2 (next-prime p) (modulo (* g (cdr T)) N)

(+ k 2) t (add T QQ R N)))

(else (stage2 p g (+ k 2) t (add T QQ R N))))))))))))

As an example, consider the factorization of the 99th repunit, the number that consists of 99 consecutive 1s, which is computed as (10^99-1)/9. The factors 3, 3, 37, 67, 199, 397, 21649, 34849, 333667, and 513239 are found by trial division or the rho method, leaving a 70-digit cofactor. The elliptic curve method finds a 19-digit factor 1344628210313298373 using the lucky curve with seed 85398978821858534277806684680913743239224200284672112948006322676318, leaving a remaining 51-digit prime co-factor 362853724342990469324766235474268869786311886053883, thus completing the factorization:

`> (ec-factor 250411029487608433927757216420194735307370292135006432870660366092481700801`

53000 2120000 85398978821858534277806684680913743239224200284672112948006322676318)

1344628210313298373

Here’s another example. On September 14, 1998, Conrad Curry found a 53-digit factor of 2^{677}-1 = 1943118631 · 531132717139346021081 · 978146583988637765536217 · P53 · P?? using bounds *B*_{1} = 11000000 and *B*_{2} = 100*B*_{1} with lucky curve *S* = 8689346476060549; with benefit of hindsight, we are able to reduce those bounds substantially:

`> (define (mersenne n) (- (expt 2 n) 1))`

> (define x (/ (mersenne 677) 1943118631 531132717139346021081 978146583988637765536217))

> (ec-factor x 9000000 16000000 8689346476060549)

53625112691923843508117942311516428173021903300344567

Curry’s accomplishment stood as a record for about fifteen months (that’s a long time in the factoring business). The current record elliptic-curve factor is a 73-digit factor of 2^{1181}-1 found by the team of Joppe Bos, Thorsten Kleinjung, Arjen Lenstra, and Peter Montgomery using a program running partly on a cluster of PlayStation 3 computers.

With the addition of the second stage, our elliptic curve factorization program is reasonably powerful; it has been used to find several 25-digit factors, which, notwithstanding the occasional record factorization as mentioned above, is about the limit of elliptic curve factorization. But elliptic curve factorization is generally slow, and our specific implementation is slower still, as we eschewed several algorithmic tricks in the interest of simplicity. There are fast implementations of elliptic curve factorization, but they are quite complicated; for instance, the GNU implementation contains 263 files and weighs in at 4.5MB of code, not counting the required big-integer library.

In addition to the elliptic arithmetic from the previous exercise, `ec-factor`

uses `ilog`

from the Standard Prelude and all of the machinery from the next-prime exercise. You can run the program at http://programmingpraxis.codepad.org/dN59DMk0.

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 p-1 function?

In line 6, q should read Q-sub-z (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/elliptic-curve-prime-factorisation/

[…] 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/modern-elliptic-curve-factorization-part-1/#comment-1192: