Title: Prime factorization
1Prime factorization
- implementations in a functional language
2Introduction
Introduction
Fermats algorithm
Pollards rho algorithm
- Goal
- Get a better understanding of the
implementation and application of different
factorization algorithms (Fermats Pollards
rho Quadratic sieve Elliptic curve)
Elliptic curve factorization
Summary
3Fermats algorithm
Introduction
Fermats algorithm
- Observation
- All composite numbers can be
written as the difference between two squared
numbers i.e.
Pollards rho algorithm
Elliptic curve factorization
Summary
4Fermats algorithm
Introduction
- Algorithm
- Assume n is an odd number(otherwise factor out
2 until is odd). - Define
- Iteratively find .If is a
square then and are factors
of .If then stop and report
as a prime.
Fermats algorithm
Pollards rho algorithm
Elliptic curve factorization
Summary
5Fermats algorithm
Introduction
Fermats algorithm
Pollards rho algorithm
Elliptic curve factorization
- Is the algorithm correct
- Does it terminate
Summary
6Fermats algorithm
Introduction
- Correctness
- The algorithm is correct iff
- Assume . Then
Fermats algorithm
Pollards rho algorithm
Elliptic curve factorization
Summary
Now assume . Then
Leading to the factor
7Fermats algorithm
Introduction
Fermats algorithm
Pollards rho algorithm
- Termination
- Termination follows trivially from the
fact that we iterate over a finite range.
Elliptic curve factorization
Summary
8Fermats algorithm
Introduction
Fermats algorithm
(define (fermat-single n) (let ((s (get-sqrt
n)) (r (cdr s)) (m (- (expt r
2) n)) (r-stop (/ ( n 1) 2)))
(letrec ((iterator (lambda ()
(if (gt r r-stop)
(cons n ()) (begin
(set! s (get-sqrt m))
(if (car s) (cons
( r (cdr s)) (- r (cdr s)))
(begin (set! m
( m ( 2 r) 1))
(set! r ( r 1))
(iterator)))))))) (if (car s)
(cons r r) (iterator)))))
Pollards rho algorithm
Elliptic curve factorization
Summary
9Fermats algorithm
Introduction
Fermats algorithm
Pollards rho algorithm
Elliptic curve factorization
Summary
10Pollards rho algorithm
Introduction
Fermats algorithm
- Observation
- If and are in different
residue class modulo but in the same class
modulo a proper divisor of then
will result in a proper divisor of .
Pollards rho algorithm
Elliptic curve factorization
Summary
11Pollards rho algorithm
Introduction
- Algorithm
- Choose a random function
- Define and
- Iteratively findIf then is a
factorIf then go to step 1or report
as maybe prime
Fermats algorithm
Pollards rho algorithm
Elliptic curve factorization
Summary
12Pollards rho algorithm
Introduction
Fermats algorithm
Pollards rho algorithm
Elliptic curve factorization
Is the algorithm correct Does it terminate
Summary
13Pollards rho algorithm
Introduction
- Correctness
- Since the range of is
finitethe and values must cycle.It
should be clear that cycles twice as fast as
so if we go through a cycle with then
so .If however
then is a non-trivial factor of .
Fermats algorithm
Pollards rho algorithm
Elliptic curve factorization
Summary
14Pollards rho algorithm
Introduction
Fermats algorithm
- Termination
- Termination follows from the
cycling of the values and guaranteed termination
when cycling has happened.
Pollards rho algorithm
Elliptic curve factorization
Summary
15Pollards rho algorithm
Introduction
Fermats algorithm
(define (pollard-rho-single n) (let ((a 2)
(b 2) (c 1)) (letrec ((iterator
(lambda () (begin
(set! a (modulo ( (expt a 2) c)
n)) (set! b (modulo ( (expt b
2) c) n)) (set! b (modulo (
(expt b 2) c) n)) (let ((d (gcd
(- a b) n))) (cond ((and (gt d
1) (lt d n)) (cons d
(quotient n d))) (( d
n) (if ( c 2)
(cons n ())
(begin (set! a 2)
(set! b 2)
(set! c ( c 1))
(iterator)))) (else
(iterator)))))))) (iterator))))
Pollards rho algorithm
Elliptic curve factorization
Summary
16Pollards rho algorithm
Introduction
Fermats algorithm
The algorithm is too fasteven without
optimizationswhen the number has any small
factors (smaller than 10 digits). I have had
problems finding enough values to analyse
onthat give non-eligible running timesbut are
still feasible to factorize. (It factors
47189479742142798147947497147589257979528526917505
641 into3012764903 x 1566318025517134024710440446
4575395373798447in 25s)
Pollards rho algorithm
Elliptic curve factorization
Summary
17Pollards rho algorithm
Introduction
Fermats algorithm
Pollards rho algorithm
Elliptic curve factorization
Summary
18Elliptic curve factorization
Introduction
Fermats algorithm
- Observation
- Iteratively applying a group function to a
series of points starting on a random point in a
group defined by an elliptic curve modulo the
number we are factorizing we will eventually find
a generator for the subgroup we iterate over.
Using the order of this subgroup we can
determine a factor of n.
Pollards rho algorithm
Elliptic curve factorization
Summary
19Elliptic curve factorization
Introduction
Fermats algorithm
(define (elliptic-curve-single n) (let ((a 1)
(p (cons 0 5)) (e 2)) (letrec
((iterator (lambda ()
(begin (set! p (point-expt p e
a)) (set! e ( e 1))
(if (not (pair p)) (if
(symbol p) (cons n
()) (cons p (quotient n
p))) (iterator))))))
(iterator)))))
Pollards rho algorithm
Elliptic curve factorization
Summary
20Elliptic curve factorization
Introduction
Fermats algorithm
Pollards rho algorithm
Elliptic curve factorization
Summary
21Summary
Introduction
Fermats algorithm
Pollards rho algorithm
- The following insight was gained through the
project - The elliptic curve algorithm is not fast in its
natural form but becomes fast as elliptic
curve knowledge is applied as optimizations. - The implementation of the sieving process in
quadratic sieve is complex and confusing - A better understanding of the implemented
algorithms
Elliptic curve factorization
Summary