Factoring Lab

Receipts for factoring ideas: which work, which don’t, and how fast they stop working.

Shared with the primes explainer

Glossary

Every term is defined once, here and in the tooltips. Wording follows your reading level; links open in a new tab.

Batch GCD

If two RSA keys share a prime, gcd(N₁, N₂) reveals it instantly. Batch GCD checks millions of keys against each other without trying every pair.

Benford’s law

The chance that the first digit is d is log₁₀(1 + 1/d): about 30% for 1, 17.6% for 2, down to 4.6% for 9. Primes do not follow it exactly; their pattern depends on how far you count.

Birthday paradox

With m possible values, a repeat is likely after only about √m random picks, not m. That’s why Pollard’s rho finds a factor p in about √p steps.

Brent’s cycle detection

Instead of a tortoise and hare both moving, Brent keeps one point fixed and jumps it forward at powers of two. Fewer steps find the same loop.

CFRAC

Expand √N as a continued fraction. Every step gives a square that is almost N, and the leftover is small. Keep the leftovers made of small primes, combine them into X² ≡ Y² (mod N), and take a gcd.

Chance zero

A blank cell that the gcd rule says is allowed to have primes, but happens to have none. Expected to be rare when each cell holds many numbers.

Chebyshev’s bias

Count primes ending in remainder 3 vs 1 (mod 4): the 3s lead almost all the time. The lead is tiny and comes from how squares behave, not from a hidden pattern.

Chinese remainder theorem

For pairwise coprime moduli m₁ … mₖ, the system x ≡ rᵢ (mod mᵢ) has exactly one solution modulo m₁·…·mₖ. It combines many small remainders into one big one.

Collatz conjecture

Start anywhere: if even, halve; if odd, multiply by 3 and add 1. Every number tried (far beyond a quintillion) reaches 1. The number of steps, the stopping time, jumps around unpredictably.

Common modulus

If the same message is encrypted under one modulus N with two exponents e₁ and e₂ that share no factor, then Bézout gives a·e₁ + b·e₂ = 1 and m = c₁ᵃ·c₂ᵇ mod N. No factoring is needed.

Conjecture F

Predicts how many primes a quadratic like 4k² + 2k + 41 produces. Lines that avoid small factors (like Euler’s 41-line) are bright.

Continued fraction

Every number x can be written x = a₀ + 1/(a₁ + 1/(a₂ + …)). Stopping after k terms gives a convergent, a fraction that approximates x better than any fraction with a smaller denominator. Euclid’s algorithm computes the terms.

Coprime

a and b are coprime when gcd(a, b) = 1. Only columns whose remainder is coprime to the row length can contain primes.

Correlation

A number from −1 to 1 measuring how well two lists move together. The triangle’s mirror cells correlate strongly, but fake primes do too.

Dickman’s ρ function

ρ(u) is the chance that a random number up to x has all its prime factors below x^{1/u}. ρ(2) ≈ 0.31, ρ(3) ≈ 0.049, ρ(5) ≈ 0.00035.

Dirichlet’s theorem

For coprime a and m, the sequence a, a + m, a + 2m, … contains infinitely many primes, and each of the φ(m) allowed remainders gets about the same share.

Dispersion (evenness)

Variance of the column counts divided by what random chance would give. 1 = as uneven as random; 0.13 means primes are spread much more evenly.

Elliptic curve method

Do arithmetic on points of a random elliptic curve mod N. If the curve’s size mod p happens to be made of small primes, an impossible division appears, and the gcd that blocked it is a factor. Unlucky? Pick another curve.

Euclid’s orchard

The grid points (x, y) with gcd(x, y) = 1, the ones visible from the origin. The triangle’s rays are the fractions r/y; its blanks are the hidden trees.

Euler’s totient φ

φ(n) counts the remainders 1…n that are coprime to n. Row y of the triangle has exactly φ(y) cells that can hold primes.

Fake primes (Cramér model)

Random numbers that pass the same small-prime test as primes and appear at the same rate (1/ln n). A control: anything the fakes also show comes from divisibility.

Fermat’s factorization method

Write N = a² − b² = (a − b)(a + b). Start with a = ⌈√N⌉ and step up until a² − N is a perfect square. Fast only when p and q are close.

Floyd’s cycle detection

Move one pointer one step and another two steps. If the sequence loops they meet, and they meet within one lap of the loop, using almost no memory.

Fourier spectrum

Breaks a sequence into waves. Peaks mean repeating patterns. The primes’ peaks sit exactly at fractions like 1/2, 1/3, 1/6: the rhythms of small-prime divisibility.

Fractal dimension

Count how many boxes of shrinking size you need to cover the shape. How fast that count grows gives the dimension. The triangle’s blanks score 1.953.

Greatest common divisor (gcd)

gcd(a, b) is the largest integer dividing both. In this triangle a cell is blank exactly when gcd(remainder, row length) > 1, because then every number in it shares that factor.

Hardy–Littlewood conjecture

A formula for how many prime pairs (p, p + 2), (p, p + 6) … there are up to x. It works by checking which remainders small primes forbid, then multiplying the odds.

Håstad’s broadcast attack

With e = 3, send m to three recipients and the three ciphertexts are m³ mod N₁, N₂, N₃. The Chinese remainder theorem gives m³ mod N₁N₂N₃, and since m³ is smaller than that, an ordinary cube root returns m.

Last-digit bias (Lemke Oliver–Soundararajan)

Consecutive primes avoid repeating their last digit: repeats happen 18.5% of the time up to 10¹⁰ instead of 25%. Found in 2016; explained by Hardy–Littlewood.

Lattice reduction (LLL)

A lattice is all the whole-number combinations of some vectors. LLL finds a new set of vectors for the same lattice that are short and nearly at right angles, which makes the shortest one easy to read off.

Logical qubit

Real qubits make mistakes constantly. Error correction spreads one reliable (logical) qubit over many noisy (physical) ones. Estimates for breaking RSA count both kinds.

Lucas sequence

Vₙ(P) starts at 2 and P and follows Vₙ₊₁ = P·Vₙ − Vₙ₋₁. It behaves like αⁿ + α⁻ⁿ where α is a root of x² − Px + 1, so mod p it has a period dividing p − 1 or p + 1.

Mertens’ theorem

After crossing off multiples of all primes up to P, the share left is about 0.56/ln P. Each extra prime helps less.

Miller–Rabin test

Raise a few test numbers to big powers mod n. Primes pass every time; composites almost never do. With the right test numbers it is exact below 2⁶⁴.

Mirror symmetry (r ↔ y − r)

gcd(r, y) = gcd(y − r, y), so a column and its partner across the axis are blank together. Prime counts differ a bit; the blanks match exactly.

Möbius function μ

μ(n) = 0 if a square divides n, otherwise (−1)^(number of prime factors). It is the bookkeeping behind “cross off, add back” counting.

Modulus (mod)

In “n mod m”, m is the modulus. Clock arithmetic: numbers that differ by a multiple of m count as the same. Here, a row of length y works mod y.

Mutual information (bits)

Measured in bits: 1 bit is one perfect yes/no answer. The Lab measures how many bits a pattern gives about whether a number is prime or what its factor is.

Neural network

Layers of simple units multiply their inputs by weights, add them up and bend the result. Training nudges the weights to make fewer mistakes. A network with a hidden layer can learn rules a straight line cannot, like “this bit XOR that bit”.

Number field sieve

Like the quadratic sieve, it collects relations from numbers made of small primes, but works with two much smaller numbers per pair (a, b), one ordinary and one from a special number system, so far more relations turn up.

Pisano period

The Fibonacci numbers taken mod m repeat with a fixed period, the Pisano period. For m = 7 it is 16, so F_N mod 7 depends only on N mod 16.

Pollard’s p − 1

Raise a number to a power built from many small primes, mod N. If p − 1 divides that power, Fermat’s little theorem makes the result 1 mod p, and a gcd with N pops out p.

Pollard’s rho

Repeat x → x² + c (mod N). Secretly, the same sequence taken mod the hidden prime p must loop after about √p steps. When two values collide mod p, gcd(difference, N) reveals p.

Post-quantum cryptography

Post-quantum schemes rest on problems like lattices and hash functions, not on factoring. NIST published the first standards in August 2024 (ML-KEM, ML-DSA, SLH-DSA).

Prime gap

The distance between consecutive primes. Its average near N is ln N, but gaps that are multiples of 6 are favored because they avoid 2 and 3.

Prime number

An integer p > 1 whose only positive divisors are 1 and p. Every integer above 1 is a product of primes in exactly one way.

Prime number theorem

Near a big number N, roughly 1 in ln N numbers is prime (ln is the natural log). It predicts how many primes a window holds, not which ones.

Public and private exponent

RSA picks e (public) and d (private) with e·d ≡ 1 mod φ(N). Anyone can lock with e: c = mᵉ mod N. Only d unlocks: m = cᵈ mod N.

Quadratic residue

a is a quadratic residue mod p when x² ≡ a (mod p) has a solution. For an odd prime p, exactly half of the nonzero residues are; the Legendre symbol (a/p) says which.

Quadratic sieve

Look at (x² − N) for x near √N, keep the ones made only of small primes (the factor base), then combine some so their product is a perfect square. That gives X² ≡ Y² mod N, and gcd(X − Y, N) is often a factor.

Quantum Fourier transform

The Fourier transform splits a signal into its repeat rates. The quantum version does that to all 2ᵗ amplitudes of t qubits using only about t² gates; a classical simulation uses the FFT.

Remainder / residue

The remainder r of n divided by m, written n mod m. All numbers in one cell of row y share one remainder r, so they share every factor r has in common with y.

ROCA

The Return of Coppersmith’s Attack (2017): a key-generation library built primes as k·M + 65537ᵃ mod M. Every such key shows a recognizable fingerprint in its public modulus, and the pattern shrinks the search.

RSA

Public-key encryption whose security depends on factoring N = p·q being hard. A rule that predicted primes or factors at huge N would break it; nothing here does.

Safe prime

p is a safe prime when p = 2r + 1 with r also prime, so p − 1 has one huge prime factor and is never smooth. “Strong” primes are a looser version of the same idea.

Semiprime

N = p × q with p, q prime. Finding p and q from N is easy for small N and believed to be extremely hard for 600-digit N. That is what RSA relies on.

Shor’s algorithm

Factoring N reduces to finding the period r of aˣ mod N. A quantum computer can look at all x at once and use a Fourier transform to read r off peaks; then gcd(a^{r/2} ± 1, N) gives factors.

Sieve of Eratosthenes

List the integers, then strike out the multiples of each prime p (starting at p²). Survivors are prime. Every “blank” pattern in this app is this crossing-off.

Smooth number

N is B-smooth when every prime factor of N is at most B. 360 is 5-smooth. Smooth numbers get rarer as numbers grow, and how fast they thin out decides how fast factoring can be.

Trial division

Divide N by 2, 3, 5, 7, … up to √N. The first divisor that leaves no remainder is the smallest prime factor. Work grows like the size of that factor.

Twin primes

Prime pairs (p, p + 2). Nobody knows if there are infinitely many, but Hardy–Littlewood predicts how many and the counts match.

Ulam spiral

Diagonals of the spiral are quadratic formulas like 4k² + 2k + 41. Some formulas can’t be divisible by small primes, so their diagonals are bright.

Wheel

Only numbers coprime to 30 (remainders 1, 7, 11, 13, 17, 19, 23, 29) can be prime past 5. A wheel skips everything else; bigger wheels use more primes.

Wiener’s attack

If the private exponent d is below about N^¼/3, then k/d is a convergent of e/N, so trying each convergent reveals d and then φ(N), which splits N.

Williams’ p + 1

Pollard’s p − 1 needs p − 1 smooth. Williams’ p + 1 swaps the powers for a Lucas sequence and works when p + 1 is smooth instead (and when it is not lucky, it falls back to p − 1).

z-score

How many “typical wobbles” (standard deviations) a result is away from what chance predicts. Above about 4, we call it real.