Pollard's rho algorithm is an algorithm for integer factorization. It was invented by John Pollard in 1975.[1] It uses only a small amount of space, and its expected running time is proportional to the square root of the smallest prime factor of the composite number being factorized.
The algorithm is used to factorize a number
n=pq
p
n
g(x)
g(x)=(x2+1)\bmodn
g(x)
x1=g(2)
x2=g(g(2))
x3=g(g(g(2)))
\{xk\bmodp\}
p
Because the number of possible values for these sequences is finite, both the
\{xk\}
n
\{xk\bmodp\}
xk
O(\sqrtN)
N
\{xk\bmodp\}
\{xk\}
k1,k2
x | |
k1 |
≠
x | |
k2 |
x | |
k1 |
\equiv
x | |
k2 |
\bmodp
|x | |
k1 |
-x | |
k2 |
|
p
p
Once a sequence has a repeated value, the sequence will cycle, because each value depends only on the one before it. This structure of eventual cycling gives rise to the name "rho algorithm", owing to similarity to the shape of the Greek letter ρ when the values
x1\bmodp
x2\bmodp
This is detected by Floyd's cycle-finding algorithm: two nodes
i
j
xi
xj
\gcd(xi-xj,n)\ne1
\{xk\bmodp\}
xi\bmodp=xj\bmodp)
xi
xj
xi
xj
p
n
n
The algorithm takes as its inputs, the integer to be factored; and, a polynomial in computed modulo . In the original algorithm,
g(x)=(x2-1)\bmodn
g(x)=(x2+1)\bmodn
It performs the following steps:[2]
Pseudocode for Pollard's rho algorithm x ← 2 // starting value y ← x d ← 1 while d = 1: x ← g(x) y ← g(g(y)) d ← gcd(|x - y|, n) if d = n: return failure else: return d
Here and corresponds to and in the previous section. Note that this algorithm may fail to find a nontrivial factor even when is composite. In that case, the method can be tried again, using a starting value of x other than 2 (
0\leqx<n
g(x)=(x2+b)\bmodn
1\leqb<n-2
Let
n=8051
g(x)=(x2+1)\bmod8051
width=30 | width=60 | width=60 | ||||
---|---|---|---|---|---|---|
1 | 5 | 26 | 1 | |||
2 | 26 | 7474 | 1 | |||
3 | 677 | 871 | 97 | |||
4 | 7474 | 1481 | 1 |
Now 97 is a non-trivial factor of 8051. Starting values other than may give the cofactor (83) instead of 97. One extra iteration is shown above to make it clear that moves twice as fast as . Note that even after a repetition, the GCD can return to 1.
In 1980, Richard Brent published a faster variant of the rho algorithm. He used the same core ideas as Pollard but a different method of cycle detection, replacing Floyd's cycle-finding algorithm with the related Brent's cycle finding method.[3]
A further improvement was made by Pollard and Brent. They observed that if
\gcd(a,n)>1
\gcd(ab,n)>1
\gcd(|x-y|,n)
|x-y|
\gcd(z,n)
\gcd(z,n)=1
The algorithm is very fast for numbers with small factors, but slower in cases where all factors are large. The ρ algorithm's most remarkable success was the 1980 factorization of the Fermat number = 1238926361552897 × 93461639715357977769163558199606896584051237541638188580280321.[4] The ρ algorithm was a good choice for because the prime factor = 1238926361552897 is much smaller than the other factor. The factorization took 2 hours on a UNIVAC 1100/42.
The following table shows numbers produced by the algorithm, starting with
x=2
g(x)=(x2+1)\bmod10403
step | ||||||
---|---|---|---|---|---|---|
2 | 2 | 2 | 2 | 0 | ||
5 | 2 | 5 | 2 | 1 | ||
26 | 2 | 26 | 2 | 2 | ||
677 | 26 | 71 | 26 | 3 | ||
598 | 26 | 93 | 26 | 4 | ||
3903 | 26 | 65 | 26 | 5 | ||
3418 | 26 | 85 | 26 | 6 | ||
156 | 3418 | 55 | 85 | 7 | ||
3531 | 3418 | 97 | 85 | 8 | ||
5168 | 3418 | 17 | 85 | 9 | ||
3724 | 3418 | 88 | 85 | 10 | ||
978 | 3418 | 69 | 85 | 11 | ||
9812 | 3418 | 15 | 85 | 12 | ||
5983 | 3418 | 24 | 85 | 13 | ||
9970 | 3418 | 72 | 85 | 14 | ||
236 | 9970 | 34 | 72 | 15 | ||
3682 | 9970 | 46 | 72 | 16 | ||
2016 | 9970 | 97 | 72 | 17 | ||
7087 | 9970 | 17 | 72 | 18 | ||
10289 | 9970 | 88 | 72 | 19 | ||
2594 | 9970 | 69 | 72 | 20 | ||
8499 | 9970 | 15 | 72 | 21 | ||
4973 | 9970 | 24 | 72 | 22 | ||
2799 | 9970 | 72 | 72 | 23 |
The first repetition modulo 101 is 97 which occurs in step 17. The repetition is not detected until step 23, when
x\equivy\pmod{101}
\gcd(x-y,n)=\gcd(2799-9970,n)
p=101
If the pseudorandom number
x=g(x)
O(\sqrtp)\leO(n1/4)
. Cormen . Thomas H. . Thomas H. Cormen . Leiserson . Charles E. . Charles E. Leiserson . Rivest . Ronald L. . Ronald L. Rivest . Stein . Clifford . Clifford Stein . amp . Section 31.9: Integer factorization . . 2009 . third . MIT Press . Cambridge, MA . 975–980. 978-0-262-03384-8 . (this section discusses only Pollard's rho algorithm).