Code-Based Cryptography Primer
Coding-theory terms used on this page (tap to expand)
- Syndrome
- The result
s = H·r. Zero meansris a valid codeword; a non-zero syndrome encodes where the errors are. - Weight
- How many 1-bits a vector has. "Sparse" = low weight; the private rows have weight w/2 ( at this page's simulation parameters, at spec BIKE Level 1), and the error has weight t.
- Circulant
- A square matrix in which each row is the row above it, shifted one step to the right (wrapping around). Fully described by its first row.
- Ring F₂[x]/(xʳ−1)
- Polynomials with 0/1 coefficients where
xʳ = 1. Multiplying byxis exactly a cyclic shift — so a circulant matrix is a polynomial in this ring. - Systematic form
- A code layout where the message bits appear verbatim inside the codeword, followed by parity bits — so decoding just reads off the first block.
- LPN
- Learning Parity with Noise — recovering a secret from many noisy linear equations over F₂. The average-case hard problem underneath BIKE.
Error-Correcting Codes: The Foundation
Error-correcting codes (ECCs) allow a sender to encode data so that a receiver can detect and correct errors introduced during transmission. Cryptographers discovered that the difficulty of decoding a random linear code can be used as the basis for a public-key cryptosystem.
The idea: the private key is a structured code that's easy to decode. The public key disguises this structure so that decoding looks like solving a hard problem for anyone without the private key.
Simple Parity Check Example
A parity check matrix H defines which bit patterns are valid codewords. If a received word r satisfies H · r = 0, it's valid. Otherwise, the non-zero result (the syndrome) reveals where errors occurred.
QC-MDPC Codes
Quasi-Cyclic Moderate-Density Parity-Check (QC-MDPC) codes are the mathematical backbone of BIKE.
- Quasi-Cyclic (QC): The parity check matrix H is built from circulant blocks — each block is fully determined by its first row, which is cyclically shifted to fill the remaining rows. This gives compact key representation.
- Moderate-Density Parity-Check (MDPC): H is sparse but not as sparse as classical LDPC codes. The row weight w is roughly O(√n), providing a balance between decodability and security.
- Structure: H = [H₀ | H₁] where H₀ and H₁ are r×r circulant matrices, each defined by a single row polynomial of weight w/2.
Spec BIKE Level 1: r = — each circulant block defined by a row of weight w/2 = . This page's simulation: r = , w/2 = .
See it: one row builds a whole block
The static [H₀ | H₁] box above just asserts "circulant." Here's the same idea you can poke. Toggle a bit in the first row and watch every other row — the same row shifted one step right — re-fill the block. That is what quasi-cyclic means, and why one short row is enough to store the whole matrix.
Go deeper The LPN / Syndrome-Decoding hardness assumption
BIKE's security rests on the Learning Parity with Noise (LPN) problem — specifically, the difficulty of decoding a random quasi-cyclic code. Given a random syndrome s = H · e where e is a sparse error vector, recovering e is believed to be hard even for quantum computers.
This is related to the Syndrome Decoding Problem, which has been studied since the 1960s and is NP-hard in the worst case.
From Codes to Key Encapsulation
BIKE builds a Key Encapsulation Mechanism (KEM) on top of QC-MDPC codes. The private key holder knows the sparse structure of H and can decode efficiently. Everyone else faces a hard decoding problem. Next: let's generate a BIKE keypair.
BIKE Key Generation
BIKE key generation produces a keypair using QC-MDPC code structure. This page runs the BIKE Level 1 structure at reduced parameters so every step completes instantly in the browser: r = , w = (w/2 = per block), t = . Spec BIKE Level 1 is r = , w = , t = — the table below is the published spec, not what runs here.
| Parameter Set | Security Level | r (block size) | w (row weight) | t (error weight) |
|---|---|---|---|---|
| BIKE Level 1 | Level 1 | 12,323 | 142 | 134 |
| BIKE Level 3 | Level 3 | 24,659 | 206 | 199 |
| BIKE Level 5 | Level 5 | 40,973 | 274 | 264 |
Generate a Keypair (r = , w = , t = )
Press "Generate Keypair" to create a keypair at the simulation parameters.
Key Structure
Private Key
A pair of sparse polynomials (h₀, h₁) in the ring F₂[x]/(xr − 1), each of weight w/2 — here, at spec BIKE Level 1.
These define the sparse rows of the QC-MDPC parity check matrix H = [H₀ | H₁].
Public Key
A single polynomial h = h₀⁻¹ · h₁ mod (xr − 1).
This is the systematic form of the code — knowing h without the sparse factorization doesn't help decode.
See the trapdoor: sparse private vs dense public
Generate a keypair above to see the private key's sparse structure disappear into the public key.
Key Size Comparison
BIKE achieves much smaller keys than Classic McEliece while staying in the same code-based security family. ML-KEM has the smallest keys overall. RSA-2048 is not post-quantum secure. These are spec figures at NIST security level 1 — the simulation on this page uses far smaller r, so its keys are a few dozen bytes.
Keys generated. Now let's use them to encapsulate and share a secret.
Encapsulation & Decapsulation
KEM Flow: Alice → Bob
- Alice encapsulates: Using Bob's public key, generates a random error vector e of weight t ( in this simulation; at spec BIKE Level 1), computes ciphertext c = e · [1 | h]ᵀ and derives shared secret K from e.
- Bob decapsulates: Using his private key (h₀, h₁), computes syndrome s = H · cᵀ, then applies the Black-Gray-Flip (BGF) decoder to recover e, and derives the same K.
- Shared secret match: KAlice = KBob — used to key a symmetric cipher.
The Black-Gray-Flip Decoder
BIKE uses the Black-Gray-Flip (BGF) decoder for decapsulation. The name is the algorithm: Black and Gray are two masks it builds, and the flips it makes to each are what separate BGF from an ordinary threshold bit-flipper. Each of the steps below is a phase you can watch execute in the visualization further down.
- Compute the syndrome: s = H · cᵀ. Zero means no errors; every non-zero bit is an unsatisfied parity check.
- Set the threshold and classify: T is recomputed from the live syndrome weight each iteration (affine rule, floored at the majority value (d+1)/2 where d = w/2 = here). Count each bit's unsatisfied checks: counter ≥ T is Black; within τ below T is Gray.
- Flip every Black bit — all at once, against the same start-of-iteration syndrome. Gray bits are recorded and deliberately left alone for now.
- Black correction pass (first iteration): recount against the updated syndrome and un-flip any Black bit that still shows ≥ (d+1)/2 unsatisfied checks. A bit flipped in error usually looks worse afterwards — this is how BGF walks back its own mistakes, and it is the single largest reason its failure rate beats a plain bit-flipping decoder.
- Gray correction pass (first iteration): the bits that were on the bubble get a second look now that the Black flips have moved the syndrome underneath them; those that have crossed (d+1)/2 are flipped. Later iterations are plain threshold flips, and the decoder stops when the syndrome reaches zero — or gives up after iterations.
Decapsulation Failure Rate (DFR): BIKE has a non-zero DFR — the decoder may fail for some error patterns, so BIKE is not suitable for protocols requiring perfect correctness. Two different numbers, and they are not interchangeable:
- Spec BIKE Level 1 (r = , t = ): DFR < 2−128, by design — an event nobody will ever observe. ML-KEM's < 2−139 is comparably negligible.
- This page (r = , t = ): the reduced parameters are far weaker, and the measured rate is roughly 0.5% — about 2−7.6, or 1 decode in 200. That is not a flaw in the decoder; it is what shrinking r by a factor of 21 costs you. Do not read the 2−128 figure onto anything that runs in this tab.
The rate quoted above is not a constant typed into the page — measure it yourself in the DFR lab below, and push the error weight up to watch it climb.
Try It: Encapsulate & Decapsulate
⚠ Generate a keypair in first.
DFR Lab: Break the Decoder
A decapsulation failure rate is normally a number you are asked to believe. Here it is a number you can produce. Each trial below plants a fresh random error of the weight you choose, forms the real syndrome, runs the real BGF decoder, and checks that it recovered exactly the planted error — a zero syndrome reached with a different error vector still means Alice and Bob derive different secrets, so it counts as a failure. A fresh keypair is drawn every 50 trials, so the result averages over keys instead of reporting one lucky key.
Watch for the waterfall: the rate sits near zero while t is inside what the code can correct, turns sharply over a narrow band, and pins at 100%. That knee — not the headline constant — is the shape of every code-based KEM's correctness argument. It is also why choosing r and t is the whole security-versus-correctness tradeoff in BIKE.
End-to-End: KEM + AES-256-GCM
BIKE + AES-256-GCM provides a complete post-quantum secure channel. But how does BIKE compare to the standardized ML-KEM?
BIKE vs ML-KEM Comparison
Side-by-Side: Key Sizes, Ciphertext, Performance
| Property | BIKE Level 1 | ML-KEM-512 | BIKE Level 3 | ML-KEM-768 | BIKE Level 5 | ML-KEM-1024 |
|---|---|---|---|---|---|---|
| Security Level | 1 | 1 | 3 | 3 | 5 | 5 |
| Public Key (bytes) | 1,541 | 800 | 3,083 | 1,184 | 5,122 | 1,568 |
| Ciphertext (bytes) | 1,573 | 768 | 3,115 | 1,088 | 5,154 | 1,568 |
| Shared Secret (bytes) | 32 | 32 | 32 | 32 | 32 | 32 |
| Security Assumption | QC-MDPC Decoding | QC-MDPC Decoding | QC-MDPC Decoding | |||
| vs | Module-LWE | vs | Module-LWE | vs | Module-LWE | |
| Decap Failure Rate (spec) | < 2−128 | < 2−139 | < 2−192 | < 2−164 | < 2−256 | < 2−174 |
| NIST Status | Round 4 Alt | Standardized | Round 4 Alt | Standardized | Round 4 Alt | Standardized |
Every figure in this table is a specification figure at full parameters. The simulation running on this page uses r = instead of , and its measured decoding-failure rate is around 0.5% — roughly 2−7.6, not 2−128. The DFR lab in Panel 3 measures it live.
Visual: Public Key + Ciphertext Sizes
Security Assumption Diversity
ML-KEM (Lattice-Based)
Built on the Module Learning With Errors (Module-LWE) problem. Lattice problems are relatively new in cryptography (studied since ~1996). ML-KEM is the NIST standard — the recommended default.
Recommended DefaultBIKE (Code-Based)
Built on the Syndrome Decoding / QC-MDPC Decoding problem. Code-based cryptography dates to McEliece (1978) — the oldest post-quantum proposal still unbroken. BIKE provides algorithmic diversity.
Diversity Use CasesKey tradeoff: BIKE has much smaller keys than Classic McEliece (the other code-based candidate) but has a non-zero decapsulation failure rate, unlike ML-KEM's essentially negligible DFR. For protocols requiring perfect correctness, ML-KEM is the better choice.
Both KEMs have their place. Let's explore why code-based post-quantum crypto matters for the future.
Why Code-Based Post-Quantum Crypto Matters
Cryptographic Diversity
The NIST post-quantum standardization process selected ML-KEM (lattice-based) as the primary KEM standard, then in March 2025 selected the code-based HQC as a backup on a different mathematical assumption — precisely because no single assumption should be a single point of failure. The isogeny-based candidate SIKE made the same diversity argument and was broken outright in 2022 by a classical attack, which is a reminder that diversity is a hedge, not a guarantee.
If a breakthrough attack against lattice problems emerges, code-based schemes like HQC, BIKE, and Classic McEliece would remain secure — and vice versa. That is the cryptographic diversity argument, and it is why the syndrome-decoding problem this page is built on is worth understanding even though BIKE itself did not advance.
45+ Years of Cryptanalysis
Robert McEliece proposed the first code-based public-key cryptosystem in 1978 — making it the oldest post-quantum proposal still considered secure. The core hardness assumption (syndrome decoding) has withstood decades of cryptanalytic effort.
- 1978: McEliece cryptosystem proposed (Goppa codes)
- 1986: Niederreiter dual formulation
- 2013: Misoczki et al. propose MDPC-McEliece — precursor to BIKE
- 2017: BIKE submitted to NIST PQC competition
- 2022: BIKE advances to NIST Round 4 alongside Classic McEliece, HQC, and SIKE
- 2025 (March): NIST selects HQC as the backup KEM to ML-KEM (NIST IR 8545). BIKE was not selected — NIST cited HQC's clearer security proof and BIKE's reliance on a decoder whose failure rate is argued rather than proven.
- Today: BIKE has no NIST standardization path. It remains a studied, implemented design (it ships in Open Quantum Safe's
liboqs) and its QC-MDPC decoding problem is still unbroken — but if you need a standards-track code-based KEM, that is HQC, and if you need a KEM at all, the default is ML-KEM.
This matters for how you read the rest of this page: BIKE is worth understanding because bit-flipping decoders and the DFR tradeoff are genuinely instructive, not because you should be planning to deploy it.
BIKE's Role in the PQ Landscape
BIKE occupies a specific niche in the post-quantum ecosystem:
- Compact alternative to Classic McEliece: Public keys ~1.5 KB vs ~261 KB at Level 1
- Same mathematical family: Both rely on the hardness of decoding random codes
- Tradeoff: BIKE has non-zero DFR; Classic McEliece has zero DFR but enormous keys
- Use cases: Where ML-KEM is primary but code-based diversity is desired as a backup or in hybrid constructions
Why This Matters in 2026+
Post-quantum migration is underway across the internet. The critical lesson from decades of cryptographic history:
Don't put all your eggs in one mathematical basket.
ML-KEM should be the default choice for most deployments. But organizations with long-term security requirements should consider hybrid approaches that include code-based schemes like BIKE — ensuring that a breakthrough against lattices doesn't compromise everything at once.
Explore More
ML-KEM (Kyber) — The standardized lattice-based KEM crypto-lab-mceliece-gate
Classic McEliece — Same code-based family, different tradeoffs crypto-lab-dilithium-seal
ML-DSA (Dilithium) — Lattice-based digital signatures crypto-lab-sphincs-ledger
SLH-DSA (SPHINCS+) — Hash-based digital signatures crypto-compare
Side-by-side KEM category comparison