The secret hidden
by a little noise
A square linear system has a unique solution when its matrix is invertible. This demo samples invertible matrices modulo 97. With zero error, elimination recovers the secret. With nonzero error, solving the exact equations generally recovers a different vector; a tiny instance remains easy to attack by enumerating the possible secrets.
A system anyone can solve
Below is a public matrix A and a public vector t, both with entries modulo q = 97. Hidden behind them is a short secret vector s — every entry is −1, 0, or 1. The relationship is the plainest one in mathematics:
Set the error to zero and that e vanishes, leaving t = A·s. Press Solve and Gaussian elimination — the same procedure you learned for three equations in three unknowns — recovers s instantly and exactly, every time. There is no security here at all.
Why so small a change ruins it
Elimination works by scaling rows and subtracting them from one another. Modulo a prime, "scaling" means multiplying by numbers like 43 or 88 — there is no notion of a small multiplier to keep things tidy. So a single unit of error, multiplied by 43 and added to another row's error, multiplied again at the next step, is smeared across the whole computation within a few rows.
Noise prevents exact elimination from being a general secret-recovery method. Security requires suitable dimensions, distributions and parameters: small error does not automatically make every instance hard. LWE and Module-LWE specify such sampling problems, with Module-LWE using structured modules over polynomial rings.
The cancellation that lets the owner in
A hard problem alone is not cryptography — the legitimate recipient has to get through. Encryption picks fresh small randomness r and sends two things: a vector u = Aᵀr + e₁, and a number v = t·r + e₂ plus the message bit multiplied by ⌊q/2⌋ — a value large enough to spot from across the ring.
Decryption computes v − s·u. Expand both sides and a large term appears twice, with opposite signs:
The bulk cancels. What survives is the message bit, sitting on top of a pile of error terms that were all small to begin with. Round to whichever of 0 or ⌊q/2⌋ is nearer, and the bit falls out. Nothing here rounds with a private basis — the secret's job is to make one big term disappear.
Honest limits of this model
Three things here are toys, and it is worth naming them.
- The size4 × 4, q = 97ML-KEM works over a 256-coefficient polynomial ring with q = 3329, arranged in modules of rank 2 to 4. The ternary secret here has only 81 possibilities; it is here to be readable, not hard.
- The randomnessuniform, not GaussianML-KEM draws relevant small values from centered binomial distributions; other schemes use different distributions, and the security proofs depend on that shape. This exhibit picks uniformly in a range, which makes the slider legible but is not what gets deployed.
- The schemeone bit, no KEMThis is an LWE-inspired one-bit encryption model, not a standard-compatible implementation. ML-KEM is a key-encapsulation mechanism with compression, a Fujisaki–Okamoto transform for chosen-ciphertext security, and rejection steps this page has no equivalent of.
What is faithful is the shape: the public key really is a matrix plus a noisy product, the secret really is a short vector, decryption really does work by cancelling a shared term, and the noise budget really is the thing parameter choices are fighting over.
The bet the post-quantum standards make
ML-KEM uses this broad structured noisy-equation pattern at much larger parameters, with additional operations omitted here. No efficient classical or quantum attack is known for its intended security targets. That expectation is based on cryptanalysis of the specified problems, not a proof that merely adding noise eliminates every exploitable quantum structure.
Three views of one problem.
§147 is the geometry — why the secret stays hidden.
§152 is the decoding — why its owner still gets in.
§157 is the algebra — what the keys are actually made of.
Next: Polynomial Rings, where these plain vectors become polynomials.
Tested logic in lwe-math.js.
Sources and scope: FIPS 203 (ML-KEM, 2024) and FIPS 204 (ML-DSA, 2024). This scalar, uniform-error toy is not either standard.