Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. ·...

117
Introduction to Integer Factorisation Algorithms Richard P. Brent 12 October 2010 Copyright c R. P. Brent, 2010 Richard Brent Integer Factorisation

Transcript of Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. ·...

Page 1: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Introduction to Integer FactorisationAlgorithms

Richard P. Brent

12 October 2010

Copyright c© R. P. Brent, 2010

Richard Brent Integer Factorisation

Page 2: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Motivation – Unique Prime Factorisation

Every natural number (integer) n > 1 is a product of primepowers

n = pα11 pα2

2 · · · pαkk ,

and this representation is unique except for the ordering, i.e. itis unique if we assume that p1 < p2 < · · · pk and the exponentsαi are positive.

1001 = 7 · 11 · 13

500 = 22 · 53

232 + 1 = 641 · 6700417

Given a large integer n, how can we actually find the primefactors of n?

Richard Brent Integer Factorisation

Page 3: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Historical Example

Mn = 2n − 1 is a Mersenne number. Mersenne (1644) claimedthat

M67 = 147573952589676412927

was prime.

Lucas (1875) showed that M67 was composite, but he did notfind any factors (we’ll see later how to show that a number iscomposite without factoring it, using Fermat’s little theorem).Cole (1903) showed that

M67 = 193707721 · 761838257287,

but it took him “three years of Sundays”.Nowadays, the Magma package running on my laptop takesabout one second to find Cole’s factors of M67. The smallestMersenne number that is not completely factored is now M919.

Richard Brent Integer Factorisation

Page 4: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Historical Example

Mn = 2n − 1 is a Mersenne number. Mersenne (1644) claimedthat

M67 = 147573952589676412927

was prime.Lucas (1875) showed that M67 was composite, but he did notfind any factors (we’ll see later how to show that a number iscomposite without factoring it, using Fermat’s little theorem).

Cole (1903) showed that

M67 = 193707721 · 761838257287,

but it took him “three years of Sundays”.Nowadays, the Magma package running on my laptop takesabout one second to find Cole’s factors of M67. The smallestMersenne number that is not completely factored is now M919.

Richard Brent Integer Factorisation

Page 5: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Historical Example

Mn = 2n − 1 is a Mersenne number. Mersenne (1644) claimedthat

M67 = 147573952589676412927

was prime.Lucas (1875) showed that M67 was composite, but he did notfind any factors (we’ll see later how to show that a number iscomposite without factoring it, using Fermat’s little theorem).Cole (1903) showed that

M67 = 193707721 · 761838257287,

but it took him “three years of Sundays”.

Nowadays, the Magma package running on my laptop takesabout one second to find Cole’s factors of M67. The smallestMersenne number that is not completely factored is now M919.

Richard Brent Integer Factorisation

Page 6: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Historical Example

Mn = 2n − 1 is a Mersenne number. Mersenne (1644) claimedthat

M67 = 147573952589676412927

was prime.Lucas (1875) showed that M67 was composite, but he did notfind any factors (we’ll see later how to show that a number iscomposite without factoring it, using Fermat’s little theorem).Cole (1903) showed that

M67 = 193707721 · 761838257287,

but it took him “three years of Sundays”.Nowadays, the Magma package running on my laptop takesabout one second to find Cole’s factors of M67. The smallestMersenne number that is not completely factored is now M919.

Richard Brent Integer Factorisation

Page 7: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Algebraic Factors

Sometimes it’s easy to find some (usually not all) factors of anumber using algebra.

For example, we know that

x3 + 1 = (x + 1)(x2 − x + 1).

Put x = 2k . This gives

23k + 1 = (2k + 1)(22k − 2k + 1).

For example, 233 + 1 has a factor 211 + 1.Similarly, 1067 − 1 has a factor 10− 1 = 9.This is obvious if you write 1067 − 1 = 99 · · · 99︸ ︷︷ ︸

67 digits

.

Richard Brent Integer Factorisation

Page 8: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Algebraic Factors

Sometimes it’s easy to find some (usually not all) factors of anumber using algebra.For example, we know that

x3 + 1 = (x + 1)(x2 − x + 1).

Put x = 2k . This gives

23k + 1 = (2k + 1)(22k − 2k + 1).

For example, 233 + 1 has a factor 211 + 1.

Similarly, 1067 − 1 has a factor 10− 1 = 9.This is obvious if you write 1067 − 1 = 99 · · · 99︸ ︷︷ ︸

67 digits

.

Richard Brent Integer Factorisation

Page 9: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Algebraic Factors

Sometimes it’s easy to find some (usually not all) factors of anumber using algebra.For example, we know that

x3 + 1 = (x + 1)(x2 − x + 1).

Put x = 2k . This gives

23k + 1 = (2k + 1)(22k − 2k + 1).

For example, 233 + 1 has a factor 211 + 1.Similarly, 1067 − 1 has a factor 10− 1 = 9.

This is obvious if you write 1067 − 1 = 99 · · · 99︸ ︷︷ ︸67 digits

.

Richard Brent Integer Factorisation

Page 10: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Algebraic Factors

Sometimes it’s easy to find some (usually not all) factors of anumber using algebra.For example, we know that

x3 + 1 = (x + 1)(x2 − x + 1).

Put x = 2k . This gives

23k + 1 = (2k + 1)(22k − 2k + 1).

For example, 233 + 1 has a factor 211 + 1.Similarly, 1067 − 1 has a factor 10− 1 = 9.This is obvious if you write 1067 − 1 = 99 · · · 99︸ ︷︷ ︸

67 digits

.

Richard Brent Integer Factorisation

Page 11: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Aurifeuillian Factors

These are a different class of factorisations, related tocyclotomic polynomials. I won’t give the general case, just asimple example.

4x4 + 1 = (4x4 + 4x2 + 1)− 4x2

= (2x2 + 1)2 − (2x)2

= (2x2 + 2x + 1)(2x2 − 2x + 1)

Put x = 2k :

24k+2 + 1 = (22k+1 + 2k+1 + 1)(22k+1 − 2k+1 + 1).

For example, 2118 + 1 = (259 + 230 + 1)(259 − 230 + 1).

Richard Brent Integer Factorisation

Page 12: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Aurifeuillian Factors

These are a different class of factorisations, related tocyclotomic polynomials. I won’t give the general case, just asimple example.

4x4 + 1 = (4x4 + 4x2 + 1)− 4x2

= (2x2 + 1)2 − (2x)2

= (2x2 + 2x + 1)(2x2 − 2x + 1)

Put x = 2k :

24k+2 + 1 = (22k+1 + 2k+1 + 1)(22k+1 − 2k+1 + 1).

For example, 2118 + 1 = (259 + 230 + 1)(259 − 230 + 1).

Richard Brent Integer Factorisation

Page 13: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Aurifeuillian Factors

These are a different class of factorisations, related tocyclotomic polynomials. I won’t give the general case, just asimple example.

4x4 + 1 = (4x4 + 4x2 + 1)− 4x2

= (2x2 + 1)2 − (2x)2

= (2x2 + 2x + 1)(2x2 − 2x + 1)

Put x = 2k :

24k+2 + 1 = (22k+1 + 2k+1 + 1)(22k+1 − 2k+1 + 1).

For example, 2118 + 1 = (259 + 230 + 1)(259 − 230 + 1).

Richard Brent Integer Factorisation

Page 14: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Algebraic and Aurifeuillian factors

Aurifeuillian factors are usually different from algebraic factors.For example, 1515 + 1 has algebraic factors 15 + 1, 153 + 1,155 + 1, and Aurifeuillian factors 19231, 142111. Combiningthis information, we find:

1515 + 1 = 24 · 31 · 211 · 1531 · 19231 · 142111.

Unfortunately, algebraic and Aurifeuillian factors only apply invery special cases. They don’t give a general factoring method.

Richard Brent Integer Factorisation

Page 15: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Modular Arithmetic

Recall thata = b mod N

means that N divides (a− b). We sometimes write this

N | (a− b).

In factoring algorithms we often need to work modulo N, whereN is the integer that we are trying to factor. More formally, wework in the ring Z/NZ.

Richard Brent Integer Factorisation

Page 16: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Modular Arithmetic

Recall thata = b mod N

means that N divides (a− b). We sometimes write this

N | (a− b).

In factoring algorithms we often need to work modulo N, whereN is the integer that we are trying to factor. More formally, wework in the ring Z/NZ.

Richard Brent Integer Factorisation

Page 17: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fast Algorithms

A polynomial time algorithm is an algorithm whose running timeis at most a polynomial in the length ` of the input data.

e.g. N = 123456789 is an integer whose length is 9 (in units ofdecimal digits).Usually length is measured in units of binary digits (bits), butthis does not change the definition of polynomial-timealgorithm.A polynomial is a function like

P(x) = ax3 + bx2 + cx + d︸ ︷︷ ︸,but we can ignore the low-order terms here.Generally, “fast” = “polynomial time”, but the degree of thepolynomial and the size of the constant “a” are important inpractice.

Richard Brent Integer Factorisation

Page 18: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fast Algorithms

A polynomial time algorithm is an algorithm whose running timeis at most a polynomial in the length ` of the input data.e.g. N = 123456789 is an integer whose length is 9 (in units ofdecimal digits).

Usually length is measured in units of binary digits (bits), butthis does not change the definition of polynomial-timealgorithm.A polynomial is a function like

P(x) = ax3 + bx2 + cx + d︸ ︷︷ ︸,but we can ignore the low-order terms here.Generally, “fast” = “polynomial time”, but the degree of thepolynomial and the size of the constant “a” are important inpractice.

Richard Brent Integer Factorisation

Page 19: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fast Algorithms

A polynomial time algorithm is an algorithm whose running timeis at most a polynomial in the length ` of the input data.e.g. N = 123456789 is an integer whose length is 9 (in units ofdecimal digits).Usually length is measured in units of binary digits (bits), butthis does not change the definition of polynomial-timealgorithm.

A polynomial is a function like

P(x) = ax3 + bx2 + cx + d︸ ︷︷ ︸,but we can ignore the low-order terms here.Generally, “fast” = “polynomial time”, but the degree of thepolynomial and the size of the constant “a” are important inpractice.

Richard Brent Integer Factorisation

Page 20: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fast Algorithms

A polynomial time algorithm is an algorithm whose running timeis at most a polynomial in the length ` of the input data.e.g. N = 123456789 is an integer whose length is 9 (in units ofdecimal digits).Usually length is measured in units of binary digits (bits), butthis does not change the definition of polynomial-timealgorithm.A polynomial is a function like

P(x) = ax3 + bx2 + cx + d︸ ︷︷ ︸,but we can ignore the low-order terms here.

Generally, “fast” = “polynomial time”, but the degree of thepolynomial and the size of the constant “a” are important inpractice.

Richard Brent Integer Factorisation

Page 21: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fast Algorithms

A polynomial time algorithm is an algorithm whose running timeis at most a polynomial in the length ` of the input data.e.g. N = 123456789 is an integer whose length is 9 (in units ofdecimal digits).Usually length is measured in units of binary digits (bits), butthis does not change the definition of polynomial-timealgorithm.A polynomial is a function like

P(x) = ax3 + bx2 + cx + d︸ ︷︷ ︸,but we can ignore the low-order terms here.Generally, “fast” = “polynomial time”, but the degree of thepolynomial and the size of the constant “a” are important inpractice.

Richard Brent Integer Factorisation

Page 22: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fast Modular Exponentiation

There is a “fast” algorithm for computing

ab mod N,

using the binary representation of the exponent b, or moregenerally some “addition chain” ending in b.

This is feasible even for numbers with hundreds of digits,because the time is (at most) a cubic polynomial in the inputsize.

Richard Brent Integer Factorisation

Page 23: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fast Modular Exponentiation

There is a “fast” algorithm for computing

ab mod N,

using the binary representation of the exponent b, or moregenerally some “addition chain” ending in b.This is feasible even for numbers with hundreds of digits,because the time is (at most) a cubic polynomial in the inputsize.

Richard Brent Integer Factorisation

Page 24: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Testing PrimalityFermat’s little Theorem (FLT):If p is prime then

ap = a mod p.

Sometimes the Theorem is stated as

ap−1 = 1 mod p,

but then we need the extra condition a 6= 0 mod p.

Suppose weare given an integer N > 2. Before trying to factor N, choosesome integer a, where 1 < a < N − 1, and compute

b = aN mod N.

If b 6= a mod N, then N must be composite (otherwise get acontradiction to FLT), so it makes sense to try to factor N. Ifb = a mod N then probably N is prime, so we could be wastingour time trying to factor N. Better to check if N really is prime.This can be done “fast”, as we’ll see later.

Richard Brent Integer Factorisation

Page 25: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Testing PrimalityFermat’s little Theorem (FLT):If p is prime then

ap = a mod p.

Sometimes the Theorem is stated as

ap−1 = 1 mod p,

but then we need the extra condition a 6= 0 mod p. Suppose weare given an integer N > 2. Before trying to factor N, choosesome integer a, where 1 < a < N − 1, and compute

b = aN mod N.

If b 6= a mod N, then N must be composite (otherwise get acontradiction to FLT), so it makes sense to try to factor N.

Ifb = a mod N then probably N is prime, so we could be wastingour time trying to factor N. Better to check if N really is prime.This can be done “fast”, as we’ll see later.

Richard Brent Integer Factorisation

Page 26: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Testing PrimalityFermat’s little Theorem (FLT):If p is prime then

ap = a mod p.

Sometimes the Theorem is stated as

ap−1 = 1 mod p,

but then we need the extra condition a 6= 0 mod p. Suppose weare given an integer N > 2. Before trying to factor N, choosesome integer a, where 1 < a < N − 1, and compute

b = aN mod N.

If b 6= a mod N, then N must be composite (otherwise get acontradiction to FLT), so it makes sense to try to factor N. Ifb = a mod N then probably N is prime, so we could be wastingour time trying to factor N. Better to check if N really is prime.This can be done “fast”, as we’ll see later.

Richard Brent Integer Factorisation

Page 27: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

“Divide and Conquer” Factoring Strategy

N is a large integer that we know is composite. We want to finda nontrivial factor f of N (nontrivial means 1 < f < N).

Once f has been found, we can test f and q = N/f to see ifthey are prime; if so the factorisation of N = f · q is complete.Otherwise, we have at least reduced the problem to one or twosmaller problems (factoring f and/or q).This is an example of the very useful “divide and conquer”strategy – if you can’t immediately solve a problem, try toreduce it to one or more smaller problems.

Richard Brent Integer Factorisation

Page 28: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

“Divide and Conquer” Factoring Strategy

N is a large integer that we know is composite. We want to finda nontrivial factor f of N (nontrivial means 1 < f < N).Once f has been found, we can test f and q = N/f to see ifthey are prime; if so the factorisation of N = f · q is complete.

Otherwise, we have at least reduced the problem to one or twosmaller problems (factoring f and/or q).This is an example of the very useful “divide and conquer”strategy – if you can’t immediately solve a problem, try toreduce it to one or more smaller problems.

Richard Brent Integer Factorisation

Page 29: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

“Divide and Conquer” Factoring Strategy

N is a large integer that we know is composite. We want to finda nontrivial factor f of N (nontrivial means 1 < f < N).Once f has been found, we can test f and q = N/f to see ifthey are prime; if so the factorisation of N = f · q is complete.Otherwise, we have at least reduced the problem to one or twosmaller problems (factoring f and/or q).

This is an example of the very useful “divide and conquer”strategy – if you can’t immediately solve a problem, try toreduce it to one or more smaller problems.

Richard Brent Integer Factorisation

Page 30: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

“Divide and Conquer” Factoring Strategy

N is a large integer that we know is composite. We want to finda nontrivial factor f of N (nontrivial means 1 < f < N).Once f has been found, we can test f and q = N/f to see ifthey are prime; if so the factorisation of N = f · q is complete.Otherwise, we have at least reduced the problem to one or twosmaller problems (factoring f and/or q).This is an example of the very useful “divide and conquer”strategy – if you can’t immediately solve a problem, try toreduce it to one or more smaller problems.

Richard Brent Integer Factorisation

Page 31: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Example

Try to factor N = 1001.

It’s easy to see that 2, 3, 5 are not divisors of N, but f = 7 | N,and the quotient is q = N/f = 143.f is prime, but q is not.From q = 122 − 1 we get q = 11 · 13. Thus N = 7 · 11 · 13.

Since it is easy to divide out powers of 2, I’ll assume from nowon that N is odd.

Richard Brent Integer Factorisation

Page 32: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Example

Try to factor N = 1001.It’s easy to see that 2, 3, 5 are not divisors of N, but f = 7 | N,and the quotient is q = N/f = 143.

f is prime, but q is not.From q = 122 − 1 we get q = 11 · 13. Thus N = 7 · 11 · 13.

Since it is easy to divide out powers of 2, I’ll assume from nowon that N is odd.

Richard Brent Integer Factorisation

Page 33: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Example

Try to factor N = 1001.It’s easy to see that 2, 3, 5 are not divisors of N, but f = 7 | N,and the quotient is q = N/f = 143.f is prime, but q is not.

From q = 122 − 1 we get q = 11 · 13. Thus N = 7 · 11 · 13.

Since it is easy to divide out powers of 2, I’ll assume from nowon that N is odd.

Richard Brent Integer Factorisation

Page 34: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Example

Try to factor N = 1001.It’s easy to see that 2, 3, 5 are not divisors of N, but f = 7 | N,and the quotient is q = N/f = 143.f is prime, but q is not.From q = 122 − 1 we get q = 11 · 13. Thus N = 7 · 11 · 13.

Since it is easy to divide out powers of 2, I’ll assume from nowon that N is odd.

Richard Brent Integer Factorisation

Page 35: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Trial division

The simplest way to factor N is to divide it by 2, 3, 4, . . . until wefind some p | N. Then p is the smallest factor of N and must beprime (otherwise N would have a smaller factor).

Drawback. The time required is proportional to p. Thus, trialdivision can be very slow if p is large. Since p is the smallestprime factor of N,

p ≤√

N.

Improvements. We only need to divide by primes2,3,5,7,11, . . . (but we need a list of these or some way ofgenerating them).By the Prime Number Theorem this saves a factor of orderlog N, which is not very significant.

Richard Brent Integer Factorisation

Page 36: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Trial division

The simplest way to factor N is to divide it by 2, 3, 4, . . . until wefind some p | N. Then p is the smallest factor of N and must beprime (otherwise N would have a smaller factor).Drawback. The time required is proportional to p. Thus, trialdivision can be very slow if p is large. Since p is the smallestprime factor of N,

p ≤√

N.

Improvements. We only need to divide by primes2,3,5,7,11, . . . (but we need a list of these or some way ofgenerating them).

By the Prime Number Theorem this saves a factor of orderlog N, which is not very significant.

Richard Brent Integer Factorisation

Page 37: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Trial division

The simplest way to factor N is to divide it by 2, 3, 4, . . . until wefind some p | N. Then p is the smallest factor of N and must beprime (otherwise N would have a smaller factor).Drawback. The time required is proportional to p. Thus, trialdivision can be very slow if p is large. Since p is the smallestprime factor of N,

p ≤√

N.

Improvements. We only need to divide by primes2,3,5,7,11, . . . (but we need a list of these or some way ofgenerating them).By the Prime Number Theorem this saves a factor of orderlog N, which is not very significant.

Richard Brent Integer Factorisation

Page 38: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fermat’s MethodTrial division is good for finding small factors. Fermat (1643)proposed a method that is good for finding factors that areclose to

√N – the other extreme.

Suppose N is odd and N = uv , where 0 < u ≤ v .Let

x =v + u

2, y =

v − u2

.

Note that x and y are integers, since v ± u is even.

x + y = v , x − y = u,

N = uv = (x − y)(x + y) = x2 − y2

Fermat tries to find integers x and y satisfying the equationx2 − N = y2, with y small. Thus, he starts with x = d

√Ne, the

smallest integer whose square is ≥ N.

Richard Brent Integer Factorisation

Page 39: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fermat’s MethodTrial division is good for finding small factors. Fermat (1643)proposed a method that is good for finding factors that areclose to

√N – the other extreme.

Suppose N is odd and N = uv , where 0 < u ≤ v .Let

x =v + u

2, y =

v − u2

.

Note that x and y are integers, since v ± u is even.

x + y = v , x − y = u,

N = uv = (x − y)(x + y) = x2 − y2

Fermat tries to find integers x and y satisfying the equationx2 − N = y2, with y small. Thus, he starts with x = d

√Ne, the

smallest integer whose square is ≥ N.

Richard Brent Integer Factorisation

Page 40: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fermat’s MethodTrial division is good for finding small factors. Fermat (1643)proposed a method that is good for finding factors that areclose to

√N – the other extreme.

Suppose N is odd and N = uv , where 0 < u ≤ v .Let

x =v + u

2, y =

v − u2

.

Note that x and y are integers, since v ± u is even.

x + y = v , x − y = u,

N = uv = (x − y)(x + y) = x2 − y2

Fermat tries to find integers x and y satisfying the equationx2 − N = y2, with y small. Thus, he starts with x = d

√Ne, the

smallest integer whose square is ≥ N.

Richard Brent Integer Factorisation

Page 41: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fermat’s MethodTrial division is good for finding small factors. Fermat (1643)proposed a method that is good for finding factors that areclose to

√N – the other extreme.

Suppose N is odd and N = uv , where 0 < u ≤ v .Let

x =v + u

2, y =

v − u2

.

Note that x and y are integers, since v ± u is even.

x + y = v , x − y = u,

N = uv = (x − y)(x + y) = x2 − y2

Fermat tries to find integers x and y satisfying the equationx2 − N = y2, with y small. Thus, he starts with x = d

√Ne, the

smallest integer whose square is ≥ N.

Richard Brent Integer Factorisation

Page 42: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fermat by hand (or on a calculator)

Suppose N = 9401. We find 962 < N < 972 = 9409, so startwith x = 97 and increase x by 1 until (hopefully) we find a valuesuch that x2 − N is a perfect square.

It’s easy to increase x by 1 and update x2 − N, since(x + 1)2 − x2 = 2x + 1.

x 2x + 1 x2 − N97 195 898 197 20399 199 400 = 202

Thus N = 992 − 202 = (99− 20)(99 + 20) = 79 · 119.It would be much more work to find this by trial division!

Richard Brent Integer Factorisation

Page 43: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fermat by hand (or on a calculator)

Suppose N = 9401. We find 962 < N < 972 = 9409, so startwith x = 97 and increase x by 1 until (hopefully) we find a valuesuch that x2 − N is a perfect square.It’s easy to increase x by 1 and update x2 − N, since(x + 1)2 − x2 = 2x + 1.

x 2x + 1 x2 − N97 195 898 197 20399 199 400 = 202

Thus N = 992 − 202 = (99− 20)(99 + 20) = 79 · 119.

It would be much more work to find this by trial division!

Richard Brent Integer Factorisation

Page 44: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Fermat by hand (or on a calculator)

Suppose N = 9401. We find 962 < N < 972 = 9409, so startwith x = 97 and increase x by 1 until (hopefully) we find a valuesuch that x2 − N is a perfect square.It’s easy to increase x by 1 and update x2 − N, since(x + 1)2 − x2 = 2x + 1.

x 2x + 1 x2 − N97 195 898 197 20399 199 400 = 202

Thus N = 992 − 202 = (99− 20)(99 + 20) = 79 · 119.It would be much more work to find this by trial division!

Richard Brent Integer Factorisation

Page 45: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Problems with Fermat’s Method

I The factors u and v of N that are found by Fermat’s methodmight not be prime, so they have to be factored (but thisshould not be so hard, since they are smaller than N).

I The worst case (u = 3, v = N/3) is very slow – evenslower than trial division.

Trial division (by odd divisors) takes about u/2 steps.Fermat takes about

x −√

N =u + v

2−√

N =u2

+

(N2u−√

N)

steps,

andN2u

>√

N if u <√

N2

.

Richard Brent Integer Factorisation

Page 46: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Problems with Fermat’s Method

I The factors u and v of N that are found by Fermat’s methodmight not be prime, so they have to be factored (but thisshould not be so hard, since they are smaller than N).

I The worst case (u = 3, v = N/3) is very slow – evenslower than trial division.

Trial division (by odd divisors) takes about u/2 steps.

Fermat takes about

x −√

N =u + v

2−√

N =u2

+

(N2u−√

N)

steps,

andN2u

>√

N if u <√

N2

.

Richard Brent Integer Factorisation

Page 47: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Problems with Fermat’s Method

I The factors u and v of N that are found by Fermat’s methodmight not be prime, so they have to be factored (but thisshould not be so hard, since they are smaller than N).

I The worst case (u = 3, v = N/3) is very slow – evenslower than trial division.

Trial division (by odd divisors) takes about u/2 steps.Fermat takes about

x −√

N =u + v

2−√

N =u2

+

(N2u−√

N)

steps,

andN2u

>√

N if u <√

N2

.

Richard Brent Integer Factorisation

Page 48: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Improving Fermat – the Quadratic SieveFermat’s method tries to find x , y such that x2 − y2 = N, but itwould be enough to find x , y such that

x2 − y2 = 0 mod N,

i.e.x2 = y2 mod N,

provided x 6= ±y mod N.

Then gcd(x − y ,N) will give a factor of N.The quadratic sieve (QS) method tries to factor x2

i mod N forseveral different xi , and combine the results to get an equation

x2 = y2 mod N.

With luck (at least 50% of the time) this gives nontrivialfactors of N.

Richard Brent Integer Factorisation

Page 49: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Improving Fermat – the Quadratic SieveFermat’s method tries to find x , y such that x2 − y2 = N, but itwould be enough to find x , y such that

x2 − y2 = 0 mod N,

i.e.x2 = y2 mod N,

provided x 6= ±y mod N.Then gcd(x − y ,N) will give a factor of N.

The quadratic sieve (QS) method tries to factor x2i mod N for

several different xi , and combine the results to get an equation

x2 = y2 mod N.

With luck (at least 50% of the time) this gives nontrivialfactors of N.

Richard Brent Integer Factorisation

Page 50: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Improving Fermat – the Quadratic SieveFermat’s method tries to find x , y such that x2 − y2 = N, but itwould be enough to find x , y such that

x2 − y2 = 0 mod N,

i.e.x2 = y2 mod N,

provided x 6= ±y mod N.Then gcd(x − y ,N) will give a factor of N.The quadratic sieve (QS) method tries to factor x2

i mod N forseveral different xi , and combine the results to get an equation

x2 = y2 mod N.

With luck (at least 50% of the time) this gives nontrivialfactors of N.

Richard Brent Integer Factorisation

Page 51: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Small Example of the Quadratic SieveConsider N = 1649, so 40 <

√N < 41.

412 = 1681 = 32 = 25 mod N (∗)422 = 1764 = 115 = 5 · 23 mod N432 = 1849 = 200 = 23 · 52 mod N (∗)

Multiply the two “relations” marked (∗), giving

(41 · 43)2 = 28 · 52 = (24 · 5)2 mod N,

i.e. x2 = y2 mod N,

where x = 41 · 43 = 114 mod N, and y = 24 · 5 = 80.We were lucky, because x 6= ±y mod N.

gcd(x − y ,N) = gcd(114− 80,N) = 17,

and it’s easy to check that 17 | N, in fact N = 17 · 97. Thiswould not have been so easy to find using Fermat’s method.

Richard Brent Integer Factorisation

Page 52: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

How lucky were we?Suppose N = p · q where p, q are distinct primes, and

x2 = y2 mod N.

Thus N | (x − y)(x + y),

so p | (x − y) or p | (x + y)

and q | (x − y) or q | (x + y).

There are 4 cases. If p | (x − y) and q | (x − y) then N|(x − y),so x = y mod N and we don’t find a factor of N.Similarly, if p | (x + y) and q | (x + y) then N|(x + y), sox = −y mod N and we don’t find a factor.

However, in the other two cases we do find a factor. Forexample, if p | (x − y) and q | (x + y), we get p fromgcd(N, x − y) and q from gcd(N, x + y).If the 4 cases are equally likely, we have a 50% chance ofsuccess.

Richard Brent Integer Factorisation

Page 53: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

How lucky were we?Suppose N = p · q where p, q are distinct primes, and

x2 = y2 mod N.

Thus N | (x − y)(x + y),

so p | (x − y) or p | (x + y)

and q | (x − y) or q | (x + y).

There are 4 cases. If p | (x − y) and q | (x − y) then N|(x − y),so x = y mod N and we don’t find a factor of N.Similarly, if p | (x + y) and q | (x + y) then N|(x + y), sox = −y mod N and we don’t find a factor.However, in the other two cases we do find a factor. Forexample, if p | (x − y) and q | (x + y), we get p fromgcd(N, x − y) and q from gcd(N, x + y).

If the 4 cases are equally likely, we have a 50% chance ofsuccess.

Richard Brent Integer Factorisation

Page 54: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

How lucky were we?Suppose N = p · q where p, q are distinct primes, and

x2 = y2 mod N.

Thus N | (x − y)(x + y),

so p | (x − y) or p | (x + y)

and q | (x − y) or q | (x + y).

There are 4 cases. If p | (x − y) and q | (x − y) then N|(x − y),so x = y mod N and we don’t find a factor of N.Similarly, if p | (x + y) and q | (x + y) then N|(x + y), sox = −y mod N and we don’t find a factor.However, in the other two cases we do find a factor. Forexample, if p | (x − y) and q | (x + y), we get p fromgcd(N, x − y) and q from gcd(N, x + y).If the 4 cases are equally likely, we have a 50% chance ofsuccess.

Richard Brent Integer Factorisation

Page 55: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

A Larger ExampleLet’s try N = 1098413. Compute x2 − N for x >

√N

and try to factor x2 − N using only primes in thefactor base S = {2,3,5,7,11,13,17,19,23}:

10512 = 22 · 7 · 13 · 17 mod N10632 = 22 · 73 · 23 mod N (∗)10772 = 22 · 7 · 133 mod N (∗)11192 = 22 · 7 · 172 · 19 mod N11422 = 72 · 13 · 17 · 19 mod N12372 = 22 · 13 · 192 · 23 mod (∗)

Multiply the relations (∗) to get:

(1063 · 1077 · 1237)2 = (23 · 72 · 132 · 19 · 23)2 mod N,

i.e. 3263302 = 3916382 mod N,

and compute gcd(N,391638− 326330) = 563,giving N = 563 · 1951.

Richard Brent Integer Factorisation

Page 56: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

How to find the starred relations

If N is large we might get thousands of relations – how do wepredict which ones to multiply in order to get a square?

The problem boils down to linear algebra.Take a matrix with a column for each prime in the factor base,and a row for each relation. Enter 0 if the prime exponent iseven and 1 if it is odd.Now, we have to find a set of rows whose sum (mod 2) is allzeros.In other words, find a linear dependency between the rows ofthe matrix, working over the field F2 = {0,1} (where theoperations are addition and multiplication mod 2).

Richard Brent Integer Factorisation

Page 57: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

How to find the starred relations

If N is large we might get thousands of relations – how do wepredict which ones to multiply in order to get a square?The problem boils down to linear algebra.

Take a matrix with a column for each prime in the factor base,and a row for each relation. Enter 0 if the prime exponent iseven and 1 if it is odd.Now, we have to find a set of rows whose sum (mod 2) is allzeros.In other words, find a linear dependency between the rows ofthe matrix, working over the field F2 = {0,1} (where theoperations are addition and multiplication mod 2).

Richard Brent Integer Factorisation

Page 58: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

How to find the starred relations

If N is large we might get thousands of relations – how do wepredict which ones to multiply in order to get a square?The problem boils down to linear algebra.Take a matrix with a column for each prime in the factor base,and a row for each relation. Enter 0 if the prime exponent iseven and 1 if it is odd.

Now, we have to find a set of rows whose sum (mod 2) is allzeros.In other words, find a linear dependency between the rows ofthe matrix, working over the field F2 = {0,1} (where theoperations are addition and multiplication mod 2).

Richard Brent Integer Factorisation

Page 59: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

How to find the starred relations

If N is large we might get thousands of relations – how do wepredict which ones to multiply in order to get a square?The problem boils down to linear algebra.Take a matrix with a column for each prime in the factor base,and a row for each relation. Enter 0 if the prime exponent iseven and 1 if it is odd.Now, we have to find a set of rows whose sum (mod 2) is allzeros.

In other words, find a linear dependency between the rows ofthe matrix, working over the field F2 = {0,1} (where theoperations are addition and multiplication mod 2).

Richard Brent Integer Factorisation

Page 60: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

How to find the starred relations

If N is large we might get thousands of relations – how do wepredict which ones to multiply in order to get a square?The problem boils down to linear algebra.Take a matrix with a column for each prime in the factor base,and a row for each relation. Enter 0 if the prime exponent iseven and 1 if it is odd.Now, we have to find a set of rows whose sum (mod 2) is allzeros.In other words, find a linear dependency between the rows ofthe matrix, working over the field F2 = {0,1} (where theoperations are addition and multiplication mod 2).

Richard Brent Integer Factorisation

Page 61: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

ExampleFor example, with N = 1098413, the matrix we get is:

2 3 5 7 11 13 17 19 230 0 0 1 0 1 1 0 00 0 0 1 0 0 0 0 1 (∗)0 0 0 1 0 1 0 0 0 (∗)0 0 0 1 0 0 0 1 00 0 0 0 0 1 1 1 00 0 0 0 0 1 0 0 1 (∗)

(the numbers in grey are the primes in the factor base)

Adding the rows marked (∗), using arithmetic mod 2, we get[0 0 0 0 0 0 0 0 0

],

which means that these rows are linearly dependent over F2.Finding a linear dependency takes about the same work assolving a system of linear equations, and is feasible even if thematrix is very large (especially if it is sparse).

Richard Brent Integer Factorisation

Page 62: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

ExampleFor example, with N = 1098413, the matrix we get is:

2 3 5 7 11 13 17 19 230 0 0 1 0 1 1 0 00 0 0 1 0 0 0 0 1 (∗)0 0 0 1 0 1 0 0 0 (∗)0 0 0 1 0 0 0 1 00 0 0 0 0 1 1 1 00 0 0 0 0 1 0 0 1 (∗)

(the numbers in grey are the primes in the factor base)Adding the rows marked (∗), using arithmetic mod 2, we get[

0 0 0 0 0 0 0 0 0],

which means that these rows are linearly dependent over F2.

Finding a linear dependency takes about the same work assolving a system of linear equations, and is feasible even if thematrix is very large (especially if it is sparse).

Richard Brent Integer Factorisation

Page 63: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

ExampleFor example, with N = 1098413, the matrix we get is:

2 3 5 7 11 13 17 19 230 0 0 1 0 1 1 0 00 0 0 1 0 0 0 0 1 (∗)0 0 0 1 0 1 0 0 0 (∗)0 0 0 1 0 0 0 1 00 0 0 0 0 1 1 1 00 0 0 0 0 1 0 0 1 (∗)

(the numbers in grey are the primes in the factor base)Adding the rows marked (∗), using arithmetic mod 2, we get[

0 0 0 0 0 0 0 0 0],

which means that these rows are linearly dependent over F2.Finding a linear dependency takes about the same work assolving a system of linear equations, and is feasible even if thematrix is very large (especially if it is sparse).

Richard Brent Integer Factorisation

Page 64: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Related Factoring Methods

I Instead of just considering x2 − N we can consider severalquadratic polynomials aix2 + bix + ci whereb2

i − 4aici = N. This gives the Multiple PolynomialQuadratic Sieve (MPQS), which is faster than the quadraticsieve if the polynomials are chosen correctly.

I Instead of working over the integers modN, we can workover number fields. This gives the Number Field Sieve(NFS) which is complicated but the best method known forfactoring large N.

I QS, MPQS and NFS take a time which depends mainly onthe size of N and is more or less independent of the size ofthe factors of N (unlike trial division and other methods thatwe’ll consider later).

Richard Brent Integer Factorisation

Page 65: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Example – the Ninth Fermat NumberFermat numbers are numbers of the form 22n

+ 1.

Fermat thought they were all prime, but Euler found thefactorisation:

F5 = 641 · 6700417.

F6, F7 and F8 are not too hard to factor, but

F9 = 2424833 · c148,

where c148 is a composite number with 148 decimal digits.Using the Number Field Sieve, the factors of c148 were found:

c148 = p49 · p99,

wherep49 = 7455602825647884208337395736200454918783366342657and p99 is a prime with 99 decimal digits – you can find it bydivision!

Richard Brent Integer Factorisation

Page 66: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Example – the Ninth Fermat NumberFermat numbers are numbers of the form 22n

+ 1.Fermat thought they were all prime, but Euler found thefactorisation:

F5 = 641 · 6700417.

F6, F7 and F8 are not too hard to factor, but

F9 = 2424833 · c148,

where c148 is a composite number with 148 decimal digits.

Using the Number Field Sieve, the factors of c148 were found:

c148 = p49 · p99,

wherep49 = 7455602825647884208337395736200454918783366342657and p99 is a prime with 99 decimal digits – you can find it bydivision!

Richard Brent Integer Factorisation

Page 67: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Example – the Ninth Fermat NumberFermat numbers are numbers of the form 22n

+ 1.Fermat thought they were all prime, but Euler found thefactorisation:

F5 = 641 · 6700417.

F6, F7 and F8 are not too hard to factor, but

F9 = 2424833 · c148,

where c148 is a composite number with 148 decimal digits.Using the Number Field Sieve, the factors of c148 were found:

c148 = p49 · p99,

wherep49 = 7455602825647884208337395736200454918783366342657and p99 is a prime with 99 decimal digits – you can find it bydivision!

Richard Brent Integer Factorisation

Page 68: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Current Record

The largest number factored so far by NFS is RSA768, which isa number with 768 bits (232 decimal digits). It turned out to bea product of two primes, each having 116 decimal digits(though not close enough to be found by Fermat’s method).

3347807169895689878604416984821269081770479498371376856891

2431388982883793878002287614711652531743087737814467999489

and

3674604366679959042824463379962795263227915816434308764267

6032283815739666511279233373417143396810270092798736308917

It’s not yet feasible to factor 1024-bit (≈ 300 digit) numbers, butit might be in a few years’ time.

Richard Brent Integer Factorisation

Page 69: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Current Record

The largest number factored so far by NFS is RSA768, which isa number with 768 bits (232 decimal digits). It turned out to bea product of two primes, each having 116 decimal digits(though not close enough to be found by Fermat’s method).

3347807169895689878604416984821269081770479498371376856891

2431388982883793878002287614711652531743087737814467999489

and

3674604366679959042824463379962795263227915816434308764267

6032283815739666511279233373417143396810270092798736308917

It’s not yet feasible to factor 1024-bit (≈ 300 digit) numbers, butit might be in a few years’ time.

Richard Brent Integer Factorisation

Page 70: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

The functions Lα(N)

It is convenient to define

Lα(N) = exp((ln N)α(ln ln N)1−α),

where α is a (fixed) parameter, 0 ≤ α ≤ 1.

L1/2(N) and L1/3(N) occur in the run-time analysis of severalinteger factorisation algorithms (ECM, QS, MPQS, NFS).

Richard Brent Integer Factorisation

Page 71: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

The functions Lα(N)

It is convenient to define

Lα(N) = exp((ln N)α(ln ln N)1−α),

where α is a (fixed) parameter, 0 ≤ α ≤ 1.L1/2(N) and L1/3(N) occur in the run-time analysis of severalinteger factorisation algorithms (ECM, QS, MPQS, NFS).

Richard Brent Integer Factorisation

Page 72: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Running times

Subject to some plausible assumptions, MPQS factors aninteger N in time

O((L1/2(N))c1)

for some positive constant c1.

This is not polynomial in ` = log N, but neither is it “fullyexponential” — it is somewhere in between (sometimes calledsub-exponential).For the number field sieve, the corresponding time bound is

O((L1/3(N))c2)

for some constant c2.This is asymptotically faster, but c2 > c1 and MPQS is faster fornumbers up to about 100 decimal digits.

Richard Brent Integer Factorisation

Page 73: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Running times

Subject to some plausible assumptions, MPQS factors aninteger N in time

O((L1/2(N))c1)

for some positive constant c1.This is not polynomial in ` = log N, but neither is it “fullyexponential” — it is somewhere in between (sometimes calledsub-exponential).

For the number field sieve, the corresponding time bound is

O((L1/3(N))c2)

for some constant c2.This is asymptotically faster, but c2 > c1 and MPQS is faster fornumbers up to about 100 decimal digits.

Richard Brent Integer Factorisation

Page 74: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Running times

Subject to some plausible assumptions, MPQS factors aninteger N in time

O((L1/2(N))c1)

for some positive constant c1.This is not polynomial in ` = log N, but neither is it “fullyexponential” — it is somewhere in between (sometimes calledsub-exponential).For the number field sieve, the corresponding time bound is

O((L1/3(N))c2)

for some constant c2.

This is asymptotically faster, but c2 > c1 and MPQS is faster fornumbers up to about 100 decimal digits.

Richard Brent Integer Factorisation

Page 75: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Running times

Subject to some plausible assumptions, MPQS factors aninteger N in time

O((L1/2(N))c1)

for some positive constant c1.This is not polynomial in ` = log N, but neither is it “fullyexponential” — it is somewhere in between (sometimes calledsub-exponential).For the number field sieve, the corresponding time bound is

O((L1/3(N))c2)

for some constant c2.This is asymptotically faster, but c2 > c1 and MPQS is faster fornumbers up to about 100 decimal digits.

Richard Brent Integer Factorisation

Page 76: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Another Idea – the Pollard “p-1” MethodSuppose N = p · q where p is a prime (not too large); q mightbe prime or composite.

By Fermat’s little theorem,

2p−1 = 1 mod p.

Let E be any multiple of p − 1. Then

2E = 1 mod p,

sop | (2E − 1).

If we don’t know p but can guess a suitable E , we can compute

gcd(2E − 1,N),

and (with some luck) this will give us p.

Richard Brent Integer Factorisation

Page 77: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Another Idea – the Pollard “p-1” MethodSuppose N = p · q where p is a prime (not too large); q mightbe prime or composite.By Fermat’s little theorem,

2p−1 = 1 mod p.

Let E be any multiple of p − 1. Then

2E = 1 mod p,

sop | (2E − 1).

If we don’t know p but can guess a suitable E , we can compute

gcd(2E − 1,N),

and (with some luck) this will give us p.

Richard Brent Integer Factorisation

Page 78: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Another Idea – the Pollard “p-1” MethodSuppose N = p · q where p is a prime (not too large); q mightbe prime or composite.By Fermat’s little theorem,

2p−1 = 1 mod p.

Let E be any multiple of p − 1. Then

2E = 1 mod p,

sop | (2E − 1).

If we don’t know p but can guess a suitable E , we can compute

gcd(2E − 1,N),

and (with some luck) this will give us p.

Richard Brent Integer Factorisation

Page 79: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Another Idea – the Pollard “p-1” MethodSuppose N = p · q where p is a prime (not too large); q mightbe prime or composite.By Fermat’s little theorem,

2p−1 = 1 mod p.

Let E be any multiple of p − 1. Then

2E = 1 mod p,

sop | (2E − 1).

If we don’t know p but can guess a suitable E , we can compute

gcd(2E − 1,N),

and (with some luck) this will give us p.Richard Brent Integer Factorisation

Page 80: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Guessing E

If all the prime power factors of p − 1 are ≤ B, take

E =∏

pαii ≤B

pαii .

Because E might be large (roughly eB), we don’t usuallycompute E explicitly; instead we compute 2E mod N using aloop like:

a← 2; for i = 1,2, . . . do a← apαii mod N.

Richard Brent Integer Factorisation

Page 81: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Guessing E continued

In practice we don’t know the factors of p− 1 (because we don’tknow p), but we do know that the time for the computation isproportional to B, so we just take a fairly large value, sayB ≈ 1000000, depending on how much computer time we arewilling to use.

If we are lucky, and all the prime power factors of p− 1 are ≤ B,then we will find the factor p of N.Otherwise, we have to increase B and try again, or try anothermethod (e.g. MPQS).

Richard Brent Integer Factorisation

Page 82: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Guessing E continued

In practice we don’t know the factors of p− 1 (because we don’tknow p), but we do know that the time for the computation isproportional to B, so we just take a fairly large value, sayB ≈ 1000000, depending on how much computer time we arewilling to use.If we are lucky, and all the prime power factors of p− 1 are ≤ B,then we will find the factor p of N.

Otherwise, we have to increase B and try again, or try anothermethod (e.g. MPQS).

Richard Brent Integer Factorisation

Page 83: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Guessing E continued

In practice we don’t know the factors of p− 1 (because we don’tknow p), but we do know that the time for the computation isproportional to B, so we just take a fairly large value, sayB ≈ 1000000, depending on how much computer time we arewilling to use.If we are lucky, and all the prime power factors of p− 1 are ≤ B,then we will find the factor p of N.Otherwise, we have to increase B and try again, or try anothermethod (e.g. MPQS).

Richard Brent Integer Factorisation

Page 84: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Example

The Pollard p − 1 method is great if we are lucky enough thatp − 1 has all “small” prime factors.

For example, Nohara found a 66-decimal digit factor p ofN = 960119 − 1.It turns out that

p−1 = 22 ·3 ·5 ·7 ·17 ·23 ·31 ·163 ·401 ·617 ·4271 ·13681 ·22877 ·43397 · 203459 · 1396027 · 6995393 · 13456591 · 2110402817,

and 2110402817 is small enough (if you have a fast computer).However, this situation is unusual. A 66-digit number isextremely unlikely to have all its prime factors so small.(The chance is roughly 1 in a million.)

Richard Brent Integer Factorisation

Page 85: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Example

The Pollard p − 1 method is great if we are lucky enough thatp − 1 has all “small” prime factors.For example, Nohara found a 66-decimal digit factor p ofN = 960119 − 1.

It turns out that

p−1 = 22 ·3 ·5 ·7 ·17 ·23 ·31 ·163 ·401 ·617 ·4271 ·13681 ·22877 ·43397 · 203459 · 1396027 · 6995393 · 13456591 · 2110402817,

and 2110402817 is small enough (if you have a fast computer).However, this situation is unusual. A 66-digit number isextremely unlikely to have all its prime factors so small.(The chance is roughly 1 in a million.)

Richard Brent Integer Factorisation

Page 86: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Example

The Pollard p − 1 method is great if we are lucky enough thatp − 1 has all “small” prime factors.For example, Nohara found a 66-decimal digit factor p ofN = 960119 − 1.It turns out that

p−1 = 22 ·3 ·5 ·7 ·17 ·23 ·31 ·163 ·401 ·617 ·4271 ·13681 ·22877 ·43397 · 203459 · 1396027 · 6995393 · 13456591 · 2110402817,

and 2110402817 is small enough (if you have a fast computer).

However, this situation is unusual. A 66-digit number isextremely unlikely to have all its prime factors so small.(The chance is roughly 1 in a million.)

Richard Brent Integer Factorisation

Page 87: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Example

The Pollard p − 1 method is great if we are lucky enough thatp − 1 has all “small” prime factors.For example, Nohara found a 66-decimal digit factor p ofN = 960119 − 1.It turns out that

p−1 = 22 ·3 ·5 ·7 ·17 ·23 ·31 ·163 ·401 ·617 ·4271 ·13681 ·22877 ·43397 · 203459 · 1396027 · 6995393 · 13456591 · 2110402817,

and 2110402817 is small enough (if you have a fast computer).However, this situation is unusual. A 66-digit number isextremely unlikely to have all its prime factors so small.(The chance is roughly 1 in a million.)

Richard Brent Integer Factorisation

Page 88: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

The Dickman “rho” function

The probability that a random integer N close to x has all itsprime factors < x1/α is approximated by the Dickman “rho”function

ρ(α) ≈ α−α.

For the example given above, withα = ln(p − 1)/ ln(2110402817), we find

ρ(α) ≈ 1/1385465.

The time estimates for ECM, MPQS, NFS etc depend on theprobability of certain integers being “smooth” (having all “small”prime factors), and hence they depend on the asymptotics ofthe Dickman ρ function.

Richard Brent Integer Factorisation

Page 89: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

The Dickman “rho” function

The probability that a random integer N close to x has all itsprime factors < x1/α is approximated by the Dickman “rho”function

ρ(α) ≈ α−α.

For the example given above, withα = ln(p − 1)/ ln(2110402817), we find

ρ(α) ≈ 1/1385465.

The time estimates for ECM, MPQS, NFS etc depend on theprobability of certain integers being “smooth” (having all “small”prime factors), and hence they depend on the asymptotics ofthe Dickman ρ function.

Richard Brent Integer Factorisation

Page 90: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

The Dickman “rho” function

The probability that a random integer N close to x has all itsprime factors < x1/α is approximated by the Dickman “rho”function

ρ(α) ≈ α−α.

For the example given above, withα = ln(p − 1)/ ln(2110402817), we find

ρ(α) ≈ 1/1385465.

The time estimates for ECM, MPQS, NFS etc depend on theprobability of certain integers being “smooth” (having all “small”prime factors), and hence they depend on the asymptotics ofthe Dickman ρ function.

Richard Brent Integer Factorisation

Page 91: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Worst Case for the Pollard p − 1 method

If p − 1 = 2q where q is a prime, then the Pollard “p − 1”method is very slow.

(p,q) is called a “Sophie Germain” pair after Marie-SophieGermain (1776–1831). There seem to be infinitely many suchpairs, e.g. (5,2), (7,3), (11,5), (23,11), but no one has provedthis.The problem is similar to the problem of twin primes, that ispairs (p,p + 2) where p and p + 2 are both prime.

Richard Brent Integer Factorisation

Page 92: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Worst Case for the Pollard p − 1 method

If p − 1 = 2q where q is a prime, then the Pollard “p − 1”method is very slow.(p,q) is called a “Sophie Germain” pair after Marie-SophieGermain (1776–1831). There seem to be infinitely many suchpairs, e.g. (5,2), (7,3), (11,5), (23,11), but no one has provedthis.

The problem is similar to the problem of twin primes, that ispairs (p,p + 2) where p and p + 2 are both prime.

Richard Brent Integer Factorisation

Page 93: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Worst Case for the Pollard p − 1 method

If p − 1 = 2q where q is a prime, then the Pollard “p − 1”method is very slow.(p,q) is called a “Sophie Germain” pair after Marie-SophieGermain (1776–1831). There seem to be infinitely many suchpairs, e.g. (5,2), (7,3), (11,5), (23,11), but no one has provedthis.The problem is similar to the problem of twin primes, that ispairs (p,p + 2) where p and p + 2 are both prime.

Richard Brent Integer Factorisation

Page 94: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

The Elliptic Curve Method (ECM)

The set G = {1,2, . . . ,p − 1} forms a group of order p − 1 withthe operation “multiplication mod p” if p is a prime.

The Pollard p − 1 method works well if the group order is“smooth” – meaning that all its prime factors are small.In Lenstra’s Elliptic Curve Method (ECM), we can choosedifferent groups with orders close to (but not usually equal to) p,until we are lucky and find one whose order is sufficientlysmooth.By a result of Hasse, the group orders are in the interval(p + 1− 2

√p,p + 1 + 2

√p).

ECM is the best method for finding “small” factors p of largenumbers N, say factors p < N1/3.

Richard Brent Integer Factorisation

Page 95: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

The Elliptic Curve Method (ECM)

The set G = {1,2, . . . ,p − 1} forms a group of order p − 1 withthe operation “multiplication mod p” if p is a prime.The Pollard p − 1 method works well if the group order is“smooth” – meaning that all its prime factors are small.

In Lenstra’s Elliptic Curve Method (ECM), we can choosedifferent groups with orders close to (but not usually equal to) p,until we are lucky and find one whose order is sufficientlysmooth.By a result of Hasse, the group orders are in the interval(p + 1− 2

√p,p + 1 + 2

√p).

ECM is the best method for finding “small” factors p of largenumbers N, say factors p < N1/3.

Richard Brent Integer Factorisation

Page 96: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

The Elliptic Curve Method (ECM)

The set G = {1,2, . . . ,p − 1} forms a group of order p − 1 withthe operation “multiplication mod p” if p is a prime.The Pollard p − 1 method works well if the group order is“smooth” – meaning that all its prime factors are small.In Lenstra’s Elliptic Curve Method (ECM), we can choosedifferent groups with orders close to (but not usually equal to) p,until we are lucky and find one whose order is sufficientlysmooth.

By a result of Hasse, the group orders are in the interval(p + 1− 2

√p,p + 1 + 2

√p).

ECM is the best method for finding “small” factors p of largenumbers N, say factors p < N1/3.

Richard Brent Integer Factorisation

Page 97: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

The Elliptic Curve Method (ECM)

The set G = {1,2, . . . ,p − 1} forms a group of order p − 1 withthe operation “multiplication mod p” if p is a prime.The Pollard p − 1 method works well if the group order is“smooth” – meaning that all its prime factors are small.In Lenstra’s Elliptic Curve Method (ECM), we can choosedifferent groups with orders close to (but not usually equal to) p,until we are lucky and find one whose order is sufficientlysmooth.By a result of Hasse, the group orders are in the interval(p + 1− 2

√p,p + 1 + 2

√p).

ECM is the best method for finding “small” factors p of largenumbers N, say factors p < N1/3.

Richard Brent Integer Factorisation

Page 98: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

The Elliptic Curve Method (ECM)

The set G = {1,2, . . . ,p − 1} forms a group of order p − 1 withthe operation “multiplication mod p” if p is a prime.The Pollard p − 1 method works well if the group order is“smooth” – meaning that all its prime factors are small.In Lenstra’s Elliptic Curve Method (ECM), we can choosedifferent groups with orders close to (but not usually equal to) p,until we are lucky and find one whose order is sufficientlysmooth.By a result of Hasse, the group orders are in the interval(p + 1− 2

√p,p + 1 + 2

√p).

ECM is the best method for finding “small” factors p of largenumbers N, say factors p < N1/3.

Richard Brent Integer Factorisation

Page 99: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Digression – Elliptic CurvesAn elliptic curve E is the set of points (x , y) satisfying a cubicpolynomial equation, which without much loss of generality wecan assume to be

y2 = x3 + ax + b

(the so-called Weierstrass normal form). For technical reasonswe add a point at infinity∞.

We’ll assume that x and y are in a finite field GF(q), whereq = pk is a prime power. p is called the characteristic. Inapplications, the cases q = 2k and q = p (large) are common.It is possible to define an abelian group on E . Algorithms thatdepend on a group structure, such as Pollard p − 1 (forfactoring) or Diffie-Hellman/El Gamal (for cryptography) can begeneralised to work in the group of an elliptic curve, giving riseto Lenstra’s elliptic curve method (ECM) and elliptic curvecryptography (ECC), respectively.Elliptic curves can also be used for primality testing (ECPP).

Richard Brent Integer Factorisation

Page 100: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Digression – Elliptic CurvesAn elliptic curve E is the set of points (x , y) satisfying a cubicpolynomial equation, which without much loss of generality wecan assume to be

y2 = x3 + ax + b

(the so-called Weierstrass normal form). For technical reasonswe add a point at infinity∞.We’ll assume that x and y are in a finite field GF(q), whereq = pk is a prime power. p is called the characteristic. Inapplications, the cases q = 2k and q = p (large) are common.

It is possible to define an abelian group on E . Algorithms thatdepend on a group structure, such as Pollard p − 1 (forfactoring) or Diffie-Hellman/El Gamal (for cryptography) can begeneralised to work in the group of an elliptic curve, giving riseto Lenstra’s elliptic curve method (ECM) and elliptic curvecryptography (ECC), respectively.Elliptic curves can also be used for primality testing (ECPP).

Richard Brent Integer Factorisation

Page 101: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Digression – Elliptic CurvesAn elliptic curve E is the set of points (x , y) satisfying a cubicpolynomial equation, which without much loss of generality wecan assume to be

y2 = x3 + ax + b

(the so-called Weierstrass normal form). For technical reasonswe add a point at infinity∞.We’ll assume that x and y are in a finite field GF(q), whereq = pk is a prime power. p is called the characteristic. Inapplications, the cases q = 2k and q = p (large) are common.It is possible to define an abelian group on E . Algorithms thatdepend on a group structure, such as Pollard p − 1 (forfactoring) or Diffie-Hellman/El Gamal (for cryptography) can begeneralised to work in the group of an elliptic curve, giving riseto Lenstra’s elliptic curve method (ECM) and elliptic curvecryptography (ECC), respectively.

Elliptic curves can also be used for primality testing (ECPP).

Richard Brent Integer Factorisation

Page 102: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Digression – Elliptic CurvesAn elliptic curve E is the set of points (x , y) satisfying a cubicpolynomial equation, which without much loss of generality wecan assume to be

y2 = x3 + ax + b

(the so-called Weierstrass normal form). For technical reasonswe add a point at infinity∞.We’ll assume that x and y are in a finite field GF(q), whereq = pk is a prime power. p is called the characteristic. Inapplications, the cases q = 2k and q = p (large) are common.It is possible to define an abelian group on E . Algorithms thatdepend on a group structure, such as Pollard p − 1 (forfactoring) or Diffie-Hellman/El Gamal (for cryptography) can begeneralised to work in the group of an elliptic curve, giving riseto Lenstra’s elliptic curve method (ECM) and elliptic curvecryptography (ECC), respectively.Elliptic curves can also be used for primality testing (ECPP).

Richard Brent Integer Factorisation

Page 103: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Running time of ECM

The running time of ECM depends mainly on the size of p, andonly weakly on the size of N. Under a plausible assumption, it is

O((L1/2(p))c3M(N)),

whereM(N) = O(log N log log N log log log N)

accounts for doing arithmetic mod N.

The constant c3 ≈ c2√

2.Since p ≤ N1/2, the bound is comparable to that for MPQS(and much better if p � N1/2).

Richard Brent Integer Factorisation

Page 104: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Running time of ECM

The running time of ECM depends mainly on the size of p, andonly weakly on the size of N. Under a plausible assumption, it is

O((L1/2(p))c3M(N)),

whereM(N) = O(log N log log N log log log N)

accounts for doing arithmetic mod N.The constant c3 ≈ c2

√2.

Since p ≤ N1/2, the bound is comparable to that for MPQS(and much better if p � N1/2).

Richard Brent Integer Factorisation

Page 105: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Running time of ECM

The running time of ECM depends mainly on the size of p, andonly weakly on the size of N. Under a plausible assumption, it is

O((L1/2(p))c3M(N)),

whereM(N) = O(log N log log N log log log N)

accounts for doing arithmetic mod N.The constant c3 ≈ c2

√2.

Since p ≤ N1/2, the bound is comparable to that for MPQS(and much better if p � N1/2).

Richard Brent Integer Factorisation

Page 106: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

ECM ExamplesI factored the 10-th and 11-th Fermat numbers using ECM.

For example,

F10 = 21024 + 1 = p8 · p10 · p40 · p252,

p8 = 45592577p10 = 6487031809p40 = 4659775785220018543264560743076778192897

p252 = 130439874405 · · · 127014424577

p8 and p10 are “easy”.p40 was found by ECM, and would have been very hard to findby any other method.p252 can be found by division once the other factors are known(of course, we have to check that it is prime).

Richard Brent Integer Factorisation

Page 107: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

ECM ExamplesI factored the 10-th and 11-th Fermat numbers using ECM.For example,

F10 = 21024 + 1 = p8 · p10 · p40 · p252,

p8 = 45592577p10 = 6487031809p40 = 4659775785220018543264560743076778192897

p252 = 130439874405 · · · 127014424577

p8 and p10 are “easy”.p40 was found by ECM, and would have been very hard to findby any other method.p252 can be found by division once the other factors are known(of course, we have to check that it is prime).

Richard Brent Integer Factorisation

Page 108: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

ECM Examples continued

F11 = 22048 + 1 = p6 · p′6 · p21 · p22 · p564,

p6 = 319489p′6 = 974849

p21 = 167988556341760475137p22 = 3560841906445833920513

p564 = 1734624471 · · · 6598834177

The 21-digit and 22-digit factors were found by ECM; then it iseasy to find the 564-digit factor p564 (though proving that it isprime is not so easy).

Richard Brent Integer Factorisation

Page 109: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

ECM Record

The largest factor found by ECM is a 73-digit factor

p73 = 1808422353177349564546512035512530001279481259854248860454348989451026887

of21181 − 1

(found by Bos, Kleinjung, Lenstra and Montgomery on 7 March2010, using a cluster of PlayStation 3 game consoles).

The largest prime factor of the group order is 10801302048203.

Richard Brent Integer Factorisation

Page 110: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

ECM Record

The largest factor found by ECM is a 73-digit factor

p73 = 1808422353177349564546512035512530001279481259854248860454348989451026887

of21181 − 1

(found by Bos, Kleinjung, Lenstra and Montgomery on 7 March2010, using a cluster of PlayStation 3 game consoles).The largest prime factor of the group order is 10801302048203.

Richard Brent Integer Factorisation

Page 111: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Another of Pollard’s ideas – Pollard “rho”

John Pollard is responsible for at least three factoringalgorithms – Pollard p − 1, NFS (in part), and Pollard “rho”.

I will not describe the Pollard rho method in detail here. You canfind a description on Wikipedia at http://en.wikipedia.org/wiki/Pollard’s_rho_algorithm or in thereferences at the end of these slides.Pollard rho is relatively easy to program and finds a small primefactor p in expected time O(p1/2M(N)). This is faster than trialdivision unless p is very small, and faster than ECM if p < 1010

(approximately).There is also an analogous “Pollard rho” algorithm for solvingthe discrete logarithm problem – in fact Wiener’s parallelversion of Pollard rho is the best known algorithm for crackingelliptic curve cryptosystems.

Richard Brent Integer Factorisation

Page 112: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Another of Pollard’s ideas – Pollard “rho”

John Pollard is responsible for at least three factoringalgorithms – Pollard p − 1, NFS (in part), and Pollard “rho”.I will not describe the Pollard rho method in detail here. You canfind a description on Wikipedia at http://en.wikipedia.org/wiki/Pollard’s_rho_algorithm or in thereferences at the end of these slides.

Pollard rho is relatively easy to program and finds a small primefactor p in expected time O(p1/2M(N)). This is faster than trialdivision unless p is very small, and faster than ECM if p < 1010

(approximately).There is also an analogous “Pollard rho” algorithm for solvingthe discrete logarithm problem – in fact Wiener’s parallelversion of Pollard rho is the best known algorithm for crackingelliptic curve cryptosystems.

Richard Brent Integer Factorisation

Page 113: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Another of Pollard’s ideas – Pollard “rho”

John Pollard is responsible for at least three factoringalgorithms – Pollard p − 1, NFS (in part), and Pollard “rho”.I will not describe the Pollard rho method in detail here. You canfind a description on Wikipedia at http://en.wikipedia.org/wiki/Pollard’s_rho_algorithm or in thereferences at the end of these slides.Pollard rho is relatively easy to program and finds a small primefactor p in expected time O(p1/2M(N)). This is faster than trialdivision unless p is very small, and faster than ECM if p < 1010

(approximately).

There is also an analogous “Pollard rho” algorithm for solvingthe discrete logarithm problem – in fact Wiener’s parallelversion of Pollard rho is the best known algorithm for crackingelliptic curve cryptosystems.

Richard Brent Integer Factorisation

Page 114: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Another of Pollard’s ideas – Pollard “rho”

John Pollard is responsible for at least three factoringalgorithms – Pollard p − 1, NFS (in part), and Pollard “rho”.I will not describe the Pollard rho method in detail here. You canfind a description on Wikipedia at http://en.wikipedia.org/wiki/Pollard’s_rho_algorithm or in thereferences at the end of these slides.Pollard rho is relatively easy to program and finds a small primefactor p in expected time O(p1/2M(N)). This is faster than trialdivision unless p is very small, and faster than ECM if p < 1010

(approximately).There is also an analogous “Pollard rho” algorithm for solvingthe discrete logarithm problem – in fact Wiener’s parallelversion of Pollard rho is the best known algorithm for crackingelliptic curve cryptosystems.

Richard Brent Integer Factorisation

Page 115: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Summary

We’ve looked at several methods for factoring integers:I Trial division (simple but slow).I Fermat’s method (also simple, but slow in most cases).I Quadratic sieve (QS) and MPQS.I Number field sieve (NFS) – the best general-purpose

method.I Pollard p − 1 (fast if you are lucky).I Pollard rho (simple and effective for factors up to say 1010).I Elliptic curve method (ECM) – the best method for finding

“small” factors p, say p < 1040.

Richard Brent Integer Factorisation

Page 116: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

Factoring Strategy

A good practical strategy for factoring is:I Find small factors by trial division and perhaps Pollard rho.

When found, divide them out.I Check if the remaining number N to be factored is a prime

power!I If not, try to find factor(s) by ECM and divide them out.I If what remains is not a prime power, try MPQS or NFS.

Richard Brent Integer Factorisation

Page 117: Introduction to Integer Factorisation Algorithmsbrent/pd/math3301... · 2010. 10. 12. · Motivation – Unique Prime Factorisation Every natural number (integer) n >1 is a product

References

1. Richard Brent, Factor Tables,http://wwwmaths.anu.edu.au/~brent/factors.html(has links to other websites of interest).

2. Richard Crandall and Carl Pomerance, Prime Numbers: AComputational Perspective, second edition, Springer-Verlag,New York, 2005.

3. G. H. Hardy, E. M. Wright, A. Wiles et al, An Introduction tothe Theory of Numbers, sixth edition, Oxford University Press,2008.

4. Hans Riesel, Prime Numbers and Computer Methods forFactorization, second edition, Birkhäuser Boston, 1994.

5. Sam Wagstaff, The Cunningham Project,http://homes.cerias.purdue.edu/~ssw/cun/.

Richard Brent Integer Factorisation