Pollard's rho is the gcd idea from the Lattice Map done properly: build a number, take its gcd with
N, and hope it shares a factor. The difference is that rho builds those numbers so a factor
has to turn up, and quickly.
The algorithm
Pick a starting value x₀ and a constant c, and iterate
x → x² + c (mod N).
Run two copies: the tortoise takes one step at a time
(xᵢ), the hare takes two (x₂ᵢ).
After every step compute gcd(|xᵢ − x₂ᵢ|, N). The moment
it is bigger than 1, you have a factor.
Why it works
Let p be an unknown prime factor of N. Because (x² + c) mod N reduced
mod p is just (x mod p)² + c mod p, the same sequence is secretly
running mod p as well — and there are only p values it can take there.
So mod p it must eventually repeat, and once it repeats it cycles forever. Drawn out, a
lead-in tail followed by a loop looks like the Greek letter ρ.
By the birthday paradox, a sequence that behaves randomly among p values repeats after
only about √p steps, not p. Floyd's tortoise-and-hare spots that
cycle without storing anything: once both are inside the loop, the hare gains one place per
step and must land on the tortoise. At that moment xᵢ ≡ x₂ᵢ
(mod p), so p divides their difference and the gcd reveals it — even
though you never knew p.
When it fails
If the cycles mod every prime factor close on the same step, the gcd is N itself and
tells you nothing. The fix is to start again with a different c; the page does this
automatically and lists the attempts. Values c = 0 and c = −2 are
skipped because their sequences have extra structure that defeats the method.
What it costs
About √p steps, where p is the smallest prime factor — so at
worst about N1/4. Trial division needs about p/2. For a
semiprime with two 30-bit factors that is tens of thousands of steps instead of half a billion.
It is still exponential in the size of N, which is why serious factoring moves on to the
elliptic-curve method and the number field sieve, but it is the first method that turns
“take a gcd and hope” into something that reliably works.
Pollard's Rho — Factoring by Collision
Iterate x → x² + c (mod N) with a tortoise and a hare. Hidden
inside, the same sequence is cycling mod each prime factor p. When the hare laps the
tortoise on that hidden cycle, gcd(|xᵢ − x₂ᵢ|, N) hands you
p.
The Hidden ρ
The sequence reduced mod the factor that was found. A tail leads into a loop; the tortoise
T and hare H chase each other
until they land on the same value.
Same Sequence, Two Views
Mod N the values look like noise. Mod the factor they fall into a repeating pattern — and the
gcd is how you feel that pattern without ever seeing it.
Cost
Steps to the first factor, against what trial division and the Lattice Map heuristic would do
with the same N.
Trace
Each row is one step. The last two columns use the factor found at the end — you cannot
compute them during the run, but they show the collision the gcd was detecting.