Subset-Sum Lattice Attacks: Why the ±1/2 Shift Raises Density to 0.9408
Compare Lagarias–Odlyzko against the centered CJLOSS embedding on a high-weight knapsack where uncentered LLL fails and centered LLL succeeds.
Prerequisite: Embedding Basics
Before RSA dominated public-key cryptography, Merkle and Hellman (1978) proposed encrypting messages using the NP-hard subset-sum (knapsack) problem: given positive integer weights and target sum , find the secret bit vector . Shamir broke Merkle–Hellman's trapdoor structure in 1982, and three years later Lagarias and Odlyzko showed something even more surprising: even a completely random subset-sum with no trapdoor falls to an SVP oracle whenever the weights are large enough relative to !
Why centering around wins
Measure a subset-sum's packing tightness by its density . When , the map sends bitstrings into an interval larger than , so is typically unique. Follow the five-step embedding recipe: penalize any nonzero residual by multiplying that coordinate by a large integer so any short lattice vector must satisfy the sum exactly.
Now compare the Euclidean norm of the target in uncentered vs. centered coordinates:
| Construction | Target vector | Target Euclidean norm | SVP density bound | Failure mode |
|---|---|---|---|---|
| Lagarias–Odlyzko (1985) | (x₁, …, xₙ, 0) ∈ {0, 1}ⁿ × {0} | √(n / 2) ≈ 0.707 √n (worst-case √n) | d < 0.6463 | High-weight targets (many 1s) exceed shorter ±1 kernel relations |
| CJLOSS Centered (1992) | (x₁ − ½, …, xₙ − ½, 0, ½) ∈ {±½}ⁿ × {0} × {½} | ½ √(n + 1) ≈ 0.500 √n (exact for ALL x!) | d < 0.9408 | Above 0.9408, random lattices contain exponentially many shorter vectors |
Look at what happens when has 10 ones out of 12 bits: in Lagarias–Odlyzko, the target has squared norm , whereas homogeneous combinations like with small signed integers can easily have smaller or comparable norm without using at all! Shifting every coordinate by (and doubling the entire basis so every entry stays an exact integer: ) fixes the target's squared norm at inside a lattice whose determinant grew by !
Explicit integer CJLOSS basis (row convention)
For weights , sum , and penalty , build the integer matrix :
Multiply the first rows by and add times the last row:
To read back from a reduced row with and , compute .
Watch Lagarias–Odlyzko fail while CJLOSS succeeds in Python
Take a 12-item subset sum with 18-bit weights (density ) and a high-weight secret containing ten 1s. Run exact LLL on both embeddings side by side:
from fractions import Fraction
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
w = [160256, 137628, 203169, 195268, 189585, 167651, 157940, 153862, 241676, 139403, 138883, 155633]
secret_x = [1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1]
S = sum(wi * xi for wi, xi in zip(w, secret_x))
n, N = len(w), 100
# 1. Uncentered Lagarias-Odlyzko (homogenized):
B_lo = [[1 if j == i else (N * w[i] if j == n else 0) for j in range(n + 2)] for i in range(n)]
B_lo.append([0] * n + [-N * S, 1])
lo_row0 = lll_rows(B_lo)[0]
# 2. Centered CJLOSS (doubled to keep exact integers):
B_cj = [[2 if j == i else (2 * N * w[i] if j == n else 0) for j in range(n + 2)] for i in range(n)]
B_cj.append([-1] * n + [-2 * N * S, 1])
cj_row0 = lll_rows(B_cj)[0]
sgn = cj_row0[n + 1]
recovered_x = [(sgn * cj_row0[i] + 1) // 2 for i in range(n)]
assert recovered_x == secret_x
print("LO row[0] :", lo_row0, "<- spurious relation with -3 and 2!")
print("CJLOSS row[0] :", cj_row0, "-> recovered exact x =", recovered_x)Above density , the Gaussian heuristic falls below , meaning the lattice genuinely contains shorter vectors than the planted target — at that regime, lattice reduction hands off to combinatorial meet-in-the-middle / Howgrave-Graham–Joux (BCJ) subset-sum algorithms.