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 a1,…,ana_1, \dots, a_n and target sum S=∑i=1naixiS = \sum_{i=1}^n a_i x_i, find the secret bit vector x∈{0,1}nx \in \{0, 1\}^n. 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 nn!

Why centering {0,1}\{0, 1\} around 1/21/2 wins

Measure a subset-sum's packing tightness by its density d=n/log⁡2(max⁡iai)d = n / \log_2(\max_i a_i). When d<1d < 1, the map x↦∑aixix \mapsto \sum a_i x_i sends 2n2^n bitstrings into an interval larger than 2n2^n, so xx is typically unique. Follow the five-step embedding recipe: penalize any nonzero residual ∑aixi−S\sum a_i x_i - S by multiplying that coordinate by a large integer NN so any short lattice vector must satisfy the sum exactly.

Now compare the Euclidean norm of the target in uncentered vs. centered coordinates:

ConstructionTarget vectorTarget Euclidean normSVP density boundFailure mode
Lagarias–Odlyzko (1985)(x₁, …, xₙ, 0) ∈ {0, 1}ⁿ × {0}√(n / 2) ≈ 0.707 √n (worst-case √n)d < 0.6463High-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.9408Above 0.9408, random lattices contain exponentially many shorter vectors

Look at what happens when xx has 10 ones out of 12 bits: in Lagarias–Odlyzko, the target has squared norm 10+1=1110 + 1 = 11, whereas homogeneous combinations like a1+a2−3a3−a6−a7+a8+2a9=0a_1 + a_2 - 3 a_3 - a_6 - a_7 + a_8 + 2 a_9 = 0 with small signed integers {−3,…,2}\{-3, \dots, 2\} can easily have smaller or comparable norm without using SS at all! Shifting every coordinate by −1/2-1/2 (and doubling the entire basis so every entry stays an exact integer: 2xi−1∈{−1,+1}2 x_i - 1 \in \{-1, +1\}) fixes the target's squared norm at n⋅12+0+12=n+1n \cdot 1^2 + 0 + 1^2 = n + 1 inside a lattice whose determinant grew by 2n2^n!

Explicit integer CJLOSS basis (row convention)

For weights a1,…,ana_1, \dots, a_n, sum SS, and penalty N>n+1N > \sqrt{n + 1}, build the (n+1)×(n+2)(n + 1) \times (n + 2) integer matrix BCJLOSSB_{\mathrm{CJLOSS}}:

BCJLOSS=[20⋯02Na1002⋯02Na20⋮⋮⋱⋮⋮⋮00⋯22Nan0−1−1⋯−1−2NS1]B_{\mathrm{CJLOSS}} = \begin{bmatrix} 2 & 0 & \cdots & 0 & 2 N a_1 & 0 \\ 0 & 2 & \cdots & 0 & 2 N a_2 & 0 \\ \vdots & \vdots & \ddots & \vdots & \vdots & \vdots \\ 0 & 0 & \cdots & 2 & 2 N a_n & 0 \\ -1 & -1 & \cdots & -1 & -2 N S & 1 \end{bmatrix}

Multiply the first nn rows by x1,…,xn∈{0,1}x_1, \dots, x_n \in \{0, 1\} and add 11 times the last row:

vtarget=(2x1−1,  …,  2xn−1,  2N(∑aixi−S),  1)=(±1,…,±1,  0,  1)v_{\mathrm{target}} = \bigl(2x_1 - 1,\; \dots,\; 2x_n - 1,\; 2N(\textstyle\sum a_i x_i - S),\; 1\bigr) = (\pm 1, \dots, \pm 1,\; 0,\; 1)

To read xx back from a reduced row v=(v1,…,vn,0,s)v = (v_1, \dots, v_n, 0, s) with s∈{±1}s \in \{\pm 1\} and vi∈{±1}v_i \in \{\pm 1\}, compute xi=(s⋅vi+1)/2x_i = (s \cdot v_i + 1) / 2.

Watch Lagarias–Odlyzko fail while CJLOSS succeeds in Python

Take a 12-item subset sum with 18-bit weights (density 12/17.9≈0.67>0.646312 / 17.9 \approx 0.67 > 0.6463) and a high-weight secret xx 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 0.94080.9408, the Gaussian heuristic falls below 12n\tfrac{1}{2}\sqrt{n}, meaning the lattice genuinely contains shorter vectors than the planted {±1/2}n\{\pm 1/2\}^n target — at that regime, lattice reduction hands off to combinatorial meet-in-the-middle / Howgrave-Graham–Joux (BCJ) subset-sum algorithms.