Prerequisite: Integer Relations

Suppose you are given a composite RSA-like modulus N=pqN = p q whose prime factors you do not know, and a monic degree-dd polynomial f(x)(modN)f(x) \pmod N. Over a prime field Fp\mathbb{F}_p, Berlekamp or Cantor–Zassenhaus finds roots quickly; modulo an unfactored composite NN, computing general square roots is equivalent to factoring NN. Yet in 1996, Don Coppersmith proved that whenever an integer root x0x_0 is small — specifically ∣x0∣<N1/d−ε|x_0| < N^{1/d - \varepsilon} — lattice reduction finds x0x_0 in polynomial time without factoring NN. That single idea underpins attacks on stereotyped RSA messages, partial private-key exposure (pp's top bits leaked), and flawed prime generation (ROCA).

Step 1: Lift a modular root to an integer root

Howgrave-Graham reformulated Coppersmith's method around one elementary observation: an integer divisible by NN whose absolute value is strictly smaller than NN must be zero.

Lemma (Howgrave-Graham)

Let g(x)=∑i=0w−1cixi∈Z[x]g(x) = \sum_{i=0}^{w-1} c_i x^i \in \mathbb{Z}[x] and let X≥1X \ge 1 be an upper bound on an integer ∣x0∣≤X|x_0| \le X. Define the scaled coefficient vector g~=(c0,c1X,c2X2,…,cw−1Xw−1)\tilde{g} = (c_0, c_1 X, c_2 X^2, \dots, c_{w-1} X^{w-1}). If:

g(x0)≡0(modNm)and∥g~∥1=∑i=0w−1∣ci∣Xi<Nmg(x_0) \equiv 0 \pmod{N^m} \qquad \text{and} \qquad \|\tilde{g}\|_1 = \sum_{i=0}^{w-1} |c_i| X^i < N^m

then g(x0)=0g(x_0) = 0 holds identically over the integers Z\mathbb{Z} (and since ∥g~∥1≤w ∥g~∥2\|\tilde{g}\|_1 \le \sqrt{w}\,\|\tilde{g}\|_2, Euclidean norm ∥g~∥2<Nm/w\|\tilde{g}\|_2 < N^m / \sqrt{w} suffices).

Proof in two lines: By the triangle inequality and ∣x0∣≤X|x_0| \le X, ∣g(x0)∣≤∑∣ci∣∣x0∣i≤∑∣ci∣Xi<Nm|g(x_0)| \le \sum |c_i| |x_0|^i \le \sum |c_i| X^i < N^m. The only multiple of NmN^m in the open interval (−Nm,Nm)(-N^m, N^m) is 00, so g(x0)=0g(x_0) = 0. Once we have a polynomial g(x)∈Z[x]g(x) \in \mathbb{Z}[x] that vanishes over Z\mathbb{Z}, ordinary real/rational root-finding (Newton's method or the quadratic formula) extracts x0x_0 immediately — no modular arithmetic needed!

Step 2: Build the 3×3 shift lattice by hand

Take the composite modulus N=17947N = 17947 (secretly 131×137131 \times 137, never used by the solver) and the monic quadratic:

f(x)=x2+5329x+13048≡0(mod17947)f(x) = x^2 + 5329x + 13048 \equiv 0 \pmod{17947}

Suppose we suspect a root bounded by ∣x0∣≤X=15|x_0| \le X = 15 (here x0=11x_0 = 11 is hidden inside: 112+5329(11)+13048=71788=4×1794711^2 + 5329(11) + 13048 = 71788 = 4 \times 17947). Notice that every integer combination of the three polynomials g0(x)=Ng_0(x) = N, g1(x)=Nxg_1(x) = N x, and g2(x)=f(x)g_2(x) = f(x) automatically evaluates to 0(modN)0 \pmod N at x=x0x = x_0!

Following the row-basis embedding convention, write each polynomial's scaled coefficients (c0,  c1X,  c2X2)(c_0,\; c_1 X,\; c_2 X^2) at X=15X = 15 (X2=225X^2 = 225) as a row of B∈Z3×3B \in \mathbb{Z}^{3 \times 3}:

B=[N000NX0130485329XX2]=[1794700026920501304879935225]B = \begin{bmatrix} N & 0 & 0 \\ 0 & N X & 0 \\ 13048 & 5329 X & X^2 \end{bmatrix} = \begin{bmatrix} 17947 & 0 & 0 \\ 0 & 269205 & 0 \\ 13048 & 79935 & 225 \end{bmatrix}

Why multiply column ii by XiX^i? Because LLL minimizes the norm of the row vector, and Howgrave-Graham bounds ∑∣ci∣Xi\sum |c_i| X^i, not ∑∣ci∣\sum |c_i|. Without the XiX^i weights, LLL would happily pick a large c2c_2 that blows up c2x02c_2 x_0^2. Since BB is lower triangular, its determinant and Gaussian heuristic are immediate:

det⁡(L)=N2X3=179472⋅153≈1.087×1012,gh(L)≈32πedet⁡(L)1/3≈4,309<17,947\det(L) = N^2 X^3 = 17947^2 \cdot 15^3 \approx 1.087 \times 10^{12}, \qquad \mathrm{gh}(L) \approx \sqrt{\frac{3}{2\pi e}} \det(L)^{1/3} \approx 4{,}309 < 17{,}947

Because gh(L)≪N\mathrm{gh}(L) \ll N, we expect a shortest vector well below the NN-threshold whenever X≲N1/3≈26.2X \lesssim N^{1/3} \approx 26.2.

Step 3: Reduce with LLL and solve over the integers

Running LLL (δ=3/4\delta = 3/4) on the rows of BB yields the shortest row:

v=(4851,  −8265,  2250)=−7⋅row1−3⋅row2+10⋅row3v = (4851,\; -8265,\; 2250) = -7 \cdot \text{row}_1 - 3 \cdot \text{row}_2 + 10 \cdot \text{row}_3

Check Howgrave-Graham's exact ℓ1\ell_1 condition first: ∥v∥1=4851+8265+2250=15,366<17,947=N\|v\|_1 = 4851 + 8265 + 2250 = 15{,}366 < 17{,}947 = N! Divide the coordinates by (1,15,225)(1, 15, 225) to read off the integer polynomial:

g(x)=2250225x2−826515x+4851=10x2−551x+4851g(x) = \frac{2250}{225} x^2 - \frac{8265}{15} x + 4851 = 10x^2 - 551x + 4851

Now apply the ordinary high-school quadratic formula over R\mathbb{R}: the discriminant is Δ=(−551)2−4(10)(4851)=303601−194040=109561=3312\Delta = (-551)^2 - 4(10)(4851) = 303601 - 194040 = 109561 = 331^2, giving roots (551−331)/20=11(551 - 331)/20 = 11 and (551+331)/20=44.1(551 + 331)/20 = 44.1. Discard the non-integer root and test f(11)≡0(mod17947)f(11) \equiv 0 \pmod{17947} — root x0=11x_0 = 11 is recovered!

Why higher shifts reach N1/dN^{1/d}

Our 3×33 \times 3 basis required det⁡(L)1/3=N2/3X<N\det(L)^{1/3} = N^{2/3} X < N, capping X<N1/3X < N^{1/3} instead of Coppersmith's full N1/2N^{1/2} bound for a quadratic. Adding higher-multiplicity shifts Nm−jxif(x)jN^{m-j} x^i f(x)^j — all vanishing modulo NmN^m at x0x_0 — pushes the exponent arbitrarily close to 1/d1/d. For example, at multiplicity m=2m = 2, using the 5 shifts {N2,  N2x,  Nf(x),  Nxf(x),  f(x)2}\{N^2,\; N^2 x,\; N f(x),\; N x f(x),\; f(x)^2\} gives dimension w=5w = 5 with det⁡(L)=N6X10\det(L) = N^6 X^{10}, so det⁡(L)1/5<N2  ⟺  X<N2/5=N0.4\det(L)^{1/5} < N^2 \iff X < N^{2/5} = N^{0.4}, and as m→∞m \to \infty the exponent approaches 1/21/2.

Reproduce the full attack in pure Python

from fractions import Fraction
import math

def lll_rows(basis: list[list[int]], delta: Fraction = Fraction(3, 4)) -> list[list[int]]:
    rows = [r[:] for r in basis]
    def dot(u, v): return sum(x * y for x, y in zip(u, v))
    def gs(mat):
        ortho, mu = [], {}
        for i, r in enumerate(mat):
            rf = list(map(Fraction, r))
            v = rf[:]
            for j, o in enumerate(ortho):
                mu[i, j] = dot(rf, o) / dot(o, o)
                v = [vi - mu[i, j] * oi for vi, oi in zip(v, o)]
            ortho.append(v)
        return ortho, mu

    k = 1
    while k < len(rows):
        for j in range(k - 1, -1, -1):
            _, mu = gs(rows)
            c = round(mu[k, j])
            if c:
                rows[k] = [rk - c * rj for rk, rj in zip(rows[k], rows[j])]
        ortho, mu = gs(rows)
        if delta * dot(ortho[k - 1], ortho[k - 1]) > dot(ortho[k], ortho[k]) + mu[k, k - 1]**2 * dot(ortho[k - 1], ortho[k - 1]):
            rows[k - 1], rows[k] = rows[k], rows[k - 1]
            k = max(1, k - 1)
        else:
            k += 1
    return rows

N, a, b, X = 17947, 5329, 13048, 15
B = [
    [N, 0, 0],
    [0, N * X, 0],
    [b, a * X, X * X],
]
v = lll_rows(B)[0]
assert sum(abs(coord) for coord in v) < N, "Howgrave-Graham bound not met"

c0, c1, c2 = v[0], v[1] // X, v[2] // (X * X)
disc = c1 * c1 - 4 * c2 * c0
s = math.isqrt(disc)
roots = [(-c1 + sign * s) // (2 * c2) for sign in (-1, 1) if (-c1 + sign * s) % (2 * c2) == 0]
valid = [r for r in roots if abs(r) <= X and (r * r + a * r + b) % N == 0]
print(f"Shortest polynomial: {c2}x^2 + ({c1})x + {c0} = 0 -> modular root x0 = {valid[0]}")

Exercise: Increase the hidden root to x0=32>N1/3x_0 = 32 > N^{1/3} (recomputing b=−(x02+5329x0) mod 17947b = -(x_0^2 + 5329 x_0) \bmod 17947 with bound X=35X = 35), verify that the 3×33 \times 3 basis no longer satisfies ∥v∥1<N\|v\|_1 < N, then switch to the 5×55 \times 5 m=2m = 2 shift basis above and watch LLL recover x0=32x_0 = 32 again! Compare this shift-polynomial construction with ECDSA nonce recovery in Lattice Attacks on ECDSA and high-dimensional reduction in g6k-rs recipes.