A collision that finds a factor
Worth reading first: Any unevenness brings the match sooner.
The birthday problem is usually met as a hazard. A room of twenty-three probably contains a coincidence nobody arranged, a hash function with outputs probably yields two colliding documents after only tries, and the square root in both is the reason collisions arrive far sooner than intuition expects.
In 1975 John Pollard turned the hazard into a tool. He wanted to factor a number and he knew that a collision among remainders modulo an unknown factor would arrive after about steps — long before a collision modulo itself. The difficulty is that is unknown, so the remainders modulo cannot be computed and the collision cannot be looked for. The method’s whole content is a way of detecting a coincidence in numbers nobody can see.
A walk that has to come back
Pick a modulus , a constant , and a starting value, and apply over and over. There are only possible values, so by the pigeonhole principle some value must recur within steps. And because each value determines the next, the moment a value recurs the walk is trapped: from then on it retraces the same stretch forever.
That forces the shape in the figure. Some number of values form a tail, visited once; the rest form a cycle of length . The picture looks like the Greek letter rho, which is where the method’s name comes from, and the same shape appears whenever a deterministic process runs in a finite space — an orbit that must come back in a system with finitely many states is a rho with its tail and loop.
What pigeonhole does not say is when. It guarantees a repeat within steps. The walk above repeats after nineteen, out of a possible 338, and that is typical rather than lucky.
Why the first repeat is a birthday
Suppose the map were not but a function chosen completely at random from all functions on values. Then the walk’s successive values would be independent uniform draws for as long as it keeps visiting new values — each step applies the function to a point it has never been applied to before, and a random function’s value at a fresh point is a fresh random number.
So the walk keeps producing new values exactly as long as a sequence of independent draws avoids every earlier draw. The step at which it first repeats is the moment a room of people first contains a shared birthday, with days in the year. The chance of lasting past steps is the familiar product , and the expected number of distinct values before the repeat is about — the same that gives the average room size at which a match first appears.
That is a derivation about random functions, and is not one. It is a single, very specific polynomial, and nothing in the argument above applies to it.
The polynomial behaves as though it were random. Across four hundred primes its first-repeat time has the birthday distribution to within the sampling wobble of four hundred draws, and its mean lands within one per cent of the random-function value. This is an observation and not a theorem. Nobody has proved that has rho lengths of order for all primes, or for most of them, and the whole running-time analysis of the method rests on the observation. It is one of the better-supported unproved heuristics in computational number theory, and it is unproved.
There is also a reason to expect the fit to be imperfect. A square has two square roots, so is two-to-one: half the values modulo have no predecessor at all and can only ever be a starting point. A genuinely random function has no such constraint. That the distribution still matches as closely as it does says the constraint barely affects when the first repeat happens — the walk never gets far enough into the space for the missing preimages to matter.
Finding the repeat without remembering the walk
To detect a repeat, the obvious method stores every value and checks each new one against the store. That needs memory proportional to the walk’s length, and at the sizes where the method is useful, values may be billions.
Robert Floyd’s alternative stores two numbers. Run two copies of the walk from the same start: a tortoise that takes one step at a time and a hare that takes two. Once both are on the cycle, the hare gains one position per step, so it must catch the tortoise within one lap.
The meeting step has a clean characterisation. The tortoise at step and the hare at step hold the same value exactly when both are on the cycle and the gap between their positions is a multiple of . So the first meeting is at the smallest multiple of that is at least , which is never more than — the length of the rho. Floyd’s method finds the repeat at most one lap late, using constant memory.
The price is a factor of about three in steps, since each round moves the hare twice and the tortoise once. Richard Brent’s variant, which teleports the tortoise to the hare at each power of two instead, is usually a quarter to a third faster and is what practical implementations use. Neither changes the square root.
The shadow walks
Now take , the number to be factored, and suppose with and unknown primes. Run the walk modulo .
The crucial property of is that it respects reduction. If then , because a polynomial with whole-number coefficients commutes with taking remainders. So the walk modulo , reduced modulo , is the walk modulo — a shadow walk on only values, running in lockstep with the visible one. The same is true modulo . That is exactly the correspondence two dials turning at once describes: a residue modulo is a pair of residues modulo and , and a polynomial map acts on each dial separately.
The shadow modulo closes its rho after about steps. The visible walk modulo does not close until about steps — much later. In between, there are tortoise and hare values and that agree modulo but not modulo , so divides and does not. And that is visible: the greatest common divisor of with is , or at least a proper factor of , computed by Euclid’s algorithm with no knowledge of at all.
The two grey columns are the heart of the picture and the one thing the algorithm cannot see. It computes only the tortoise, the hare and one greatest common divisor per step. The coincidence happens entirely in a residue system defined by a number nobody knows, and the divisor computation reads it out.
The second table makes a point the arithmetic might hide. The method does not find the smallest factor; it finds whichever shadow’s rho is detected first. The expected time favours the smaller prime, since is less than , but the two are close and each rho length is a random-looking quantity with a wide spread, so either can win. When a number’s prime factors differ greatly in size, the smallest wins nearly always.
And there is a failure case worth naming. If both shadows close at the same step, the difference is divisible by and both, the divisor is itself, and nothing has been learned. The remedy is to change and start again, which gives new and effectively independent walks.
Two constants to avoid, and why
Implementations are told never to use or , and the reasons are different and both worth seeing.
With the walk is , so the -th value is . Its rho is governed entirely by the multiplicative order of modulo divisors of — a clean algebraic structure, which is precisely what the method does not want. A structured walk can have a very long tail or a very long cycle for a particular prime, and nothing about its length is birthday-like.
With the structure is less obvious and more beautiful. Write ; then . The map squares , which is the same doubling that makes the logistic map at parameter four solvable, where turns out to be the Chebyshev polynomial in disguise. The walk is therefore a disguised , and inherits its algebraic orbit lengths.
The one polynomial family that makes a chaotic map exactly solvable is the one that makes a factoring walk fail, and for the same reason: being solvable and being random are opposites, and Pollard’s method needs the second.
What it costs
If the shadow modulo behaves like a random function, its rho is about values long, and Floyd’s search spends a small multiple of that. So the cost depends on the size of the factor, not of the number being factored.
The scatter around the line is not noise in the measurement; it is the spread of the rho length itself, which for a single prime ranges over a factor of several. Averaged across sixty products the slope is close to a half. The point well below the line near is a product whose larger factor’s shadow closed very early — the same effect as the 743 above, at a larger scale.
The comparison with trial division is the reason the method mattered. Dividing by every candidate up to costs about operations. Pollard’s method costs about . A twelve-digit number with a six-digit factor takes hundreds of thousands of trial divisions and something over a thousand steps of the walk. Before the elliptic-curve method arrived in 1985, Pollard’s rho was the standard way to strip medium-sized factors off a large number, and in 1980 Brent and Pollard used it to factor the eighth Fermat number, , finding a sixteen-digit factor.
What the square root does not do is threaten well-chosen cryptographic keys. An RSA modulus is a product of two primes each around , and is steps. The method is decisive against numbers with a small factor and irrelevant against numbers designed to have none, and factoring as a whole remains hard in exactly the cases that matter.
One divisor computation in a hundred
The tables compute a greatest common divisor at every step, and in practice nobody does. A divisor computation on numbers of a few hundred digits costs far more than a squaring, and at every step but the last it returns 1.
The standard repair uses the fact that a divisor of a product is visible in the product. Multiply the differences together modulo for a hundred steps, then take one divisor of the accumulated product with . If divided any one of the hundred differences, it divides the product, and the single computation finds it. The cost falls to one divisor computation per hundred steps, plus a hundred cheap multiplications.
There is one way this goes wrong, and it is the same failure as before in a new place. If divides one of the hundred differences and divides a later one, the accumulated product is divisible by both, and the divisor is . The fix is to back up: return to the start of the batch and take divisors one step at a time until the first non-trivial one appears. Since that happens only on the last batch, it costs at most a hundred extra computations once.
Batching changes nothing about the square root, and it is worth noticing why it is allowed at all. The method never needs to know which step produced the coincidence, only that one did. A procedure that tested each candidate separately would have to test them separately; a procedure looking for a coincidence among many can pool them, because a common divisor is preserved by multiplication in a way that almost nothing else is.
Collisions sought for their own sake
The rho idea applies to anything that can be iterated, and the most direct application goes back to where this essay began: finding two inputs a hash function sends to the same output.
Iterate the hash on its own output, starting anywhere. The walk lives in a space of values for a -bit hash, so it closes a rho after about steps, and the two distinct values that lead into the joining point of the rho — the last value of the tail and the last value of the cycle — hash to the same thing. That is a collision, found with constant memory, which is exactly the saving the first calculation of the birthday bound noted a naive attack needed.
Paul van Oorschot and Michael Wiener made it parallel in 1994. Many machines each run a walk from a different start and report only distinguished points — values with, say, their first thirty bits equal to zero. Two walks that ever meet are identical from then on, so they reach the same distinguished point, and a central list of those points detects the merge. The work is shared across the machines with almost no communication, and it is the standard way a generic collision search — or a discrete-logarithm search of the kind below — is spread across many machines.
The idea outlived the factoring application, and its most important use now is in a different problem entirely.
The discrete logarithm problem asks, given and in a group of order , for . Pollard adapted the rho walk in 1978: walk through elements of the form , tracking the exponents and , and wait for a collision . The collision gives a linear equation for modulo . Its expected time is again a birthday time, about steps, with constant memory.
For the elliptic-curve groups used in modern public-key cryptography, this is the best general attack known. It is why a curve over a field of about elements provides about 128 bits of security rather than 256: the attacker’s work is the square root of the group’s size, set by the same birthday arithmetic that sets a hash function’s collision resistance. Every such system’s key length is chosen with this walk in mind.
What the tables leave out
The rho figures are drawn modulo primes small enough to fit on a page, and at that size the method is pointless — a prime of 337 is found faster by dividing. The drawings show the shape the argument relies on, not a regime where the method earns its keep.
The tables show columns the algorithm cannot compute. That is their purpose, and it is also a hazard: the reader sees why the divisor becomes 97 at step three, while the method itself sees only that it did. Nothing in a run tells the method how close it is to success, which is why its running time can only be stated as an expectation.
And the cost figure is an average over sixty products, fitted with a line. It shows that the typical cost follows closely enough to be useful. It does not show that any particular number will be split in about steps, and it cannot show the thing the analysis would need, which is a proof that the walk behaves randomly at all.
Still open: why a polynomial walks like a random function
Every running-time claim above assumes that modulo a prime has rho lengths distributed like a random function’s. The evidence is overwhelming and the proof is missing. Eric Bach showed in 1991 that the first few collisions occur at the rate a random function would give — the probability of a collision within steps is about for small compared with — but the argument does not reach the scale where the method actually finishes.
The difficulty is that the walk is deterministic and its values are polynomials of rapidly growing degree in the starting point, and bounding when two of them coincide modulo for most primes is a question about the distribution of roots of those polynomials. Proving that a specific simple map is as unstructured as a random one is the same kind of question as proving that a generator is unpredictable: easy to test, easy to believe, and without a general method.
A coincidence in numbers nobody can see
The method is worth keeping for its logic more than its speed. It exploits a coincidence it cannot observe, in a residue system defined by a number it does not know, and it converts that coincidence into something observable by a greatest common divisor — the one computation that reports on a hidden divisor without needing to name it.
And its cost is a birthday cost for a precise reason. The shadow walk is a sequence of values in a space of size , and a sequence of values in a space of size first repeats after about of them, whether the values are birthdays, hash outputs or remainders of a squared number. The room of twenty-three and the eight-digit factor are the same event at two scales, and Pollard’s contribution was noticing that a coincidence which is a nuisance in one setting is, in another, the whole of the work.
What links here
Computed from the collection, not written here: the essays that point at this one.
Shares its objects with
Essays that name at least two of the same things, and that neither author linked.
- Almost every number comes down — both name iteration, modular arithmetic
- Eighteen people, and the seventeen that escape — both name modular arithmetic, pigeonhole principle
- Numbers that wrap — both name greatest common divisor, modular arithmetic
Named objects
A dashed tag is an object no other essay names yet.
Birthday problemChinese remainder theoremCollisionFactoringGreatest common divisorIterationModular arithmeticPigeonhole principle