Factoring Lab

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

B9 · Methods that workWorks, and here’s how it scales

The number field sieve, explained

The method behind modern factoring records: for pairs where both a − b·m and a norm are smooth. Live for the smallest case, N = m² + 1; the matrix and square-root steps are explained, not run.

The idea

Pick a number m and write N = f(m) for a small polynomial f. Then for each pair (a, b) look at two numbers: a − b·m, which is an ordinary integer, and the “norm” of a − b·x in a fancier number system built from f. If both are made of small primes, you get a relation. Collect enough relations, combine them, and a square-root step produces the factors. Both numbers stay small, so smooth ones are common.

Watch it

    1. 1 · Choose the polynomial. run m = 20,000, f(x) = x² + 1, f(m) = N = 400,000,001 (= 19,801 · 20,201, shown only to check the answer).
    2. 2 · Sieve for relations. run live over coprime pairs (a, b) with |a| ≤ 1,500 and 1 ≤ b ≤ 300; keep those where both a − b·m and a² + b² factor over the primes below B.
    3. 3 · Linear algebra mod 2. not run each relation is a row of exponents mod 2 (including the Gaussian side and a few quadratic-character columns); a dependency among the rows is a subset whose products are squares on both sides.
    4. 4 · Square root in ℤ[i], then gcd. not run the algebraic square root gives γ with γ² = ∏(a − b·i) and X ≡ γ(m) turns that into a congruence of squares mod N.

    The test

    How many of the 547,657 pairs are smooth on both sides, against the usual estimate ρ(u)·ρ(v), and how the two numbers’ sizes compare with N. Then the heuristic cost of QS and against the size of N.

    Fig. B9.2Heuristic cost (log₁₀ operations) of QS and NFS against the bits of N. Formulas only, not measured

    Measuring…