Coppersmith’s Method by Hand: Finding Small Modular Roots with LLL
Build a 3×3 Howgrave-Graham shift lattice for a composite modulus, reduce it with LLL, and recover a small modular root over the integers.
Prerequisite: Integer Relations
Suppose you are given a composite RSA-like modulus whose prime factors you do not know, and a monic degree- polynomial . Over a prime field , Berlekamp or Cantor–Zassenhaus finds roots quickly; modulo an unfactored composite , computing general square roots is equivalent to factoring . Yet in 1996, Don Coppersmith proved that whenever an integer root is small — specifically — lattice reduction finds in polynomial time without factoring . That single idea underpins attacks on stereotyped RSA messages, partial private-key exposure ('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 whose absolute value is strictly smaller than must be zero.
Lemma (Howgrave-Graham)
Let and let be an upper bound on an integer . Define the scaled coefficient vector . If:
then holds identically over the integers (and since , Euclidean norm suffices).
Proof in two lines: By the triangle inequality and , . The only multiple of in the open interval is , so . Once we have a polynomial that vanishes over , ordinary real/rational root-finding (Newton's method or the quadratic formula) extracts immediately — no modular arithmetic needed!
Step 2: Build the 3×3 shift lattice by hand
Take the composite modulus (secretly , never used by the solver) and the monic quadratic:
Suppose we suspect a root bounded by (here is hidden inside: ). Notice that every integer combination of the three polynomials , , and automatically evaluates to at !
Following the row-basis embedding convention, write each polynomial's scaled coefficients at () as a row of :
Why multiply column by ? Because LLL minimizes the norm of the row vector, and Howgrave-Graham bounds , not . Without the weights, LLL would happily pick a large that blows up . Since is lower triangular, its determinant and Gaussian heuristic are immediate:
Because , we expect a shortest vector well below the -threshold whenever .
Step 3: Reduce with LLL and solve over the integers
Running LLL () on the rows of yields the shortest row:
Check Howgrave-Graham's exact condition first: ! Divide the coordinates by to read off the integer polynomial:
Now apply the ordinary high-school quadratic formula over : the discriminant is , giving roots and . Discard the non-integer root and test — root is recovered!
Why higher shifts reach
Our basis required , capping instead of Coppersmith's full bound for a quadratic. Adding higher-multiplicity shifts — all vanishing modulo at — pushes the exponent arbitrarily close to . For example, at multiplicity , using the 5 shifts gives dimension with , so , and as the exponent approaches .
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 (recomputing with bound ), verify that the basis no longer satisfies , then switch to the shift basis above and watch LLL recover again! Compare this shift-polynomial construction with ECDSA nonce recovery in Lattice Attacks on ECDSA and high-dimensional reduction in g6k-rs recipes.