L 3 W

Matrix

Attachments

Recon

The handout is a single Python file. It sets N = 15, Q = 1601, M = 30, B = 3, publishes a 30x15 matrix A and a 30-entry vector b, and its main() does nothing but print a banner. No ciphertext is computed anywhere in the file. The docstring states the model, b[i] = <A[i], s> + e[i] (mod Q) with every s[i] and e[i] in [-B, B], and asks us to recover the hidden secret vector and reconstruct the original flag. In other words this is a small Learning With Errors (LWE) instance, and the whole question is how small.

What the noise actually does to linear algebra

Without the e[i] terms, recovering s would be Gaussian elimination over GF(1601). The noise breaks that, and in this instance it breaks it completely. Before touching any lattice we asked Sage for the exact solution of the linear system:

ns = {}; exec(open('challenge.py').read().split('def main')[0], ns)
A = Matrix(GF(1601), ns['A']); b = vector(GF(1601), ns['b'])
try:
    print(A.solve_right(b))
except ValueError:
    print("A*x = b has no solution over GF(1601)")
$ sage check.sage
A*x = b has no solution over GF(1601)

The system is not merely hard, it is inconsistent. The matrix A has rank 15, so its image is only a 15-dimensional slice of GF(1601)^30, and b = A*s + e (mod Q) does not land in that slice; the exact system has no solution at all. Modular arithmetic also means the noise cannot be divided out: subtracting two samples gives a new wrapped value, not a cleaner one.

The way around this is to trade the algebraic question for a geometric one. A lattice is the set of all integer combinations of some basis rows, an infinite grid of points. Recovering s from LWE samples is equivalent to finding an unusually short vector in a suitable lattice, and the Shortest Vector Problem has no known efficient algorithm even for quantum computers, which is why NIST standardized LWE-based schemes like Kyber. But “no efficient algorithm in general” leaves plenty of room for weak instances, and finding short vectors approximately is what LLL (Lenstra-Lenstra-Lovasz reduction, a polynomial-time basis-reduction algorithm) does well.

Why this instance is attackable

LWE security is a parameter game, and the gap between the solution and the generic lattice noise floor is what decides it. We can bound both sides from the handout alone.

On the solution side, each of the 15 secret entries lives in a 7-value range, so the whole secret carries log2(7^15) = 15 * 2.807 = 42.1 bits. Once we embed a candidate (s, e) into a 46-dimensional vector (30 noise slots, 15 secret slots, 1 marker), every entry is at most B = 3 in absolute value, so the embedded solution has length at most sqrt(30*9 + 15*9 + 1) = sqrt(406) = 20.1.

On the noise-floor side, the lattice we build below has dimension d = 46 and determinant Q^30 = 1601^30 (its basis is block triangular, and only the Q block contributes). The Gaussian heuristic estimates the shortest vector of a random lattice of that dimension and volume at sqrt(d/(2*pi*e)) * det^(1/d) = sqrt(46/17.08) * 1601^(30/46) = 1.64 * 122.9 = 202.

So the solution vector is at worst ten times shorter than what the lattice expects to contain. That is a huge gap, the regime where plain LLL finds the embedded solution without any BKZ refinement, and the 30 samples for 15 unknowns are exactly what push the noise floor up by thickening the Q block.

Exploitation

Building the lattice, block by block

Start from one sample rewritten. For the true secret there exists an integer vector k (one entry per sample) such that, over the integers,

b - A*s = e - Q*k        (each entry of e is in [-3, 3])

We want a lattice that contains, for every candidate integer vector y and every integer t, the point

( Q*k - A*y + t*b ,  y ,  t )

because then the choice y = s, t = 1, with k set to the wrap vector above, produces exactly (e, s, 1), a short vector. Three blocks of rows generate it:

  • Q*I_M rows, (Q*e_i | 0 | 0). These supply the free per-coordinate multiples of Q. The equation only holds mod Q, so the difference between the integer equality and the modular one is an arbitrary multiple of Q per coordinate, and this block absorbs it at no cost to any other coordinate.
  • One row per secret coordinate, ( -A[:,j] | u_j | 0 ). Row M+j holds minus column j of A followed by a unit at position M+j. A coefficient y_j on this row adds -y_j * A[:,j] to the first block while writing y_j into the middle block. The negation is deliberate: it makes the first block compute t*b - A*y, the residual against b, rather than t*b + A*y. The middle-block unit is what makes shortness meaningful, since the candidate y itself is carried inside the vector; a short vector then genuinely means “small candidate whose A*y lands close to b”.
  • One marker row, (b | 0 | 1). It contributes one copy of b and records its coefficient t in an extra coordinate. Points with t = 0 never touch b at all, they live in the homogeneous lattice of A*y mod Q pairs, whose shortest vectors sit near the Gaussian-heuristic length of about 202, far too long to masquerade as noise. So the marker separates “matches b up to bounded error” from “random lattice junk”, and it gives us a concrete filter later, since the solution must have t = ±1.

Running LLL

The complete solver, reading A and b straight from the handout:

ns = {}; exec(open('challenge.py').read().split('def main')[0], ns)
A, b = ns['A'], ns['b']
N, Q, M, B = ns['N'], ns['Q'], ns['M'], ns['B']

dim = M + N + 1
Bm = Matrix(ZZ, dim, dim)
for i in range(M):
    Bm[i, i] = Q                      # Q*I_M: absorb the mod-Q wraps
for j in range(N):
    for i in range(M):
        Bm[M + j, i] = -A[i][j]       # column j of A, negated
    Bm[M + j, M + j] = 1              # unit in the s-part
for i in range(M):
    Bm[dim - 1, i] = b[i]             # the b offset
Bm[dim - 1, dim - 1] = 1              # the marker

def center(x, q=Q):
    x = x % q
    return x - q if x > q // 2 else x

def extract(L):
    for row in L:
        if abs(row[dim - 1]) == 1:
            sign = ZZ(row[dim - 1])
            v = [sign * ZZ(row[k]) for k in range(dim - 1)]
            e_cand = [center(v[i]) for i in range(M)]
            s_cand = [center(v[M + j]) for j in range(N)]
            if all(abs(x) <= B for x in e_cand):
                return e_cand, s_cand
    return None

res = extract(Bm.LLL())
tag = "LLL"
if res is None:
    print("[-] LLL failed, trying BKZ(30)")
    res = extract(Bm.BKZ(block_size=30)); tag = "BKZ30"
if res is None:
    print("[-] FAILED")
else:
    e_cand, s_cand = res
    print(f"[+] {tag} found candidate")
    print("[+] e =", e_cand)
    print("[+] s (from lattice) =", s_cand)
    # independent recovery: solve A*s = b - e exactly over GF(Q)
    Ae = Matrix(GF(Q), A)
    rhs = vector(GF(Q), [(b[i] - e_cand[i]) % Q for i in range(M)])
    s_int = [center(ZZ(x)) for x in Ae.solve_right(rhs)]
    print("[+] s (solved) =", s_int)
    ok = all(sum(A[i][j] * s_int[j] for j in range(N)) % Q == (b[i] - e_cand[i]) % Q
             for i in range(M))
    print("[+] full verification A*s+e==b mod Q:", ok)
    L = Bm.LLL()
    print("[+] squared norms of reduced rows (shortest first):",
          sorted([(r.norm()^2, r[-1]) for r in L])[:3])
$ sage solve.sage
[+] LLL found candidate
[+] e = [-1, 0, -3, -1, 2, -3, -1, 2, 1, 0, -2, 2, 0, 2, 2, -2, 2, -2, 1, 1, 2, 2, 1, -3, -3, 3, -1, 1, -1, 3]
[+] s (from lattice) = [0, -2, 0, -3, 0, -3, 3, 1, -1, -2, 0, -2, 2, 0, 0]
[+] s (solved) = [0, -2, 0, -3, 0, -3, 3, 1, -1, -2, 0, -2, 2, 0, 0]
[+] full verification A*s+e==b mod Q: True
[+] squared norms of reduced rows (shortest first): [(154, 1), (66201, 11), (73298, 19)]

Plain LLL finds it on the first try, and the extraction logic is where the embedding details pay off. extract keeps only reduced rows whose marker coordinate is ±1; multiplying the row by its own marker (sign = row[dim-1], applied to every entry) normalizes the orientation, because LLL is free to return the negation (-e, -s, -1) of the embedded solution. The center helper folds any non-negative residue into the balanced range [-Q/2, Q/2], so a first-block entry of, say, 1599 is read as -2. The bound check abs(x) <= B on the first block then enforces the challenge’s own noise constraint, which no unrelated lattice row can satisfy.

The verification is self-contained. The recovered e is exactly the re-centered residual (b - A*s) mod Q, and all 30 entries land in [-3, 3]. For a wrong candidate the residuals spread over the full range [0, Q), and the chance of all 30 falling within ±3 of zero mod Q is (7/1601)^30, about 10^-71. As a second, independent path, the script solves A*s = b - e over GF(1601) once e is known, which is now a consistent noiseless system, and the solved s matches the middle block of the lattice vector. The norm list at the end closes the uniqueness question, since the runner-up reduced vector has squared norm 66201 against 154, a length of 257 against 12.4, so no competing small solution exists.

From the secret to the answer

The recovered s holds at most 7^15 = 4.7 * 10^12 possibilities, those 42.1 bits again, and an NVR{...} body of even six ASCII bytes needs 48 bits. The handout computes no ciphertext either. So what is “the original FLAG”?

The payload in hand is s itself, so we read it in the direct renderings first. Shifted into non-negative digits, s+3 is 313030642131533, a digit sequence with no flag shape. Mapping the seven possible values onto letters, chr(ord('a') + x + 3), gives dbdadagecbdbfdd. Reading s+3 as a base-7 big integer and converting the 41 bits to bytes produces 01 fa 2a 91 f0 c2, non-printable in either bit order and either endianness. Nothing in s spells anything.

With the direct renderings dead but the handout still promising a flag, we widened the search across s, e, A and b, sweeping every encoding family we could think of: digit packings of s and e folded into bases 7 through 16 under both bit orders, A and b read as base-1601 integers and per-entry byte streams, pixel renders of A under bit-plane filters, e as Morse code, and more, on the order of a million decoded variants in total. The longest printable run anywhere in the sweep was seven characters of noise, and no variant contained NVR. There is no encoded flag in the handout’s numbers.

Every channel was a dead end. The remaining reading is the one the description, a single word, points at: the flag is the secret vector displayed as the matrix row it is, exactly as Python prints a list, with the square brackets swapped for the flag wrapper. The exact rendering matters: the variant without spaces after the commas and the variant with the digits concatenated were both rejected, and the verbatim list rendering was accepted and confirmed by the challenge admin.

Flag capture

NVR{0, -2, 0, -3, 0, -3, 3, 1, -1, -2, 0, -2, 2, 0, 0}