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.
- QCSD / QCCF
- Quasi-Cyclic Syndrome Decoding and Quasi-Cyclic Codeword Finding — the two average-case hard problems BIKE's security rests on: recover a sparse error from a quasi-cyclic syndrome, and find a low-weight codeword in a quasi-cyclic code.
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 QCSD / QCCF hardness assumptions
BIKE's security rests on two quasi-cyclic coding problems: Quasi-Cyclic Syndrome Decoding (QCSD) and Quasi-Cyclic Codeword Finding (QCCF). For QCSD, 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. QCCF is the key-recovery side: finding the sparse private rows hidden inside the public key.
Both are quasi-cyclic versions of the generic Syndrome Decoding and Codeword Finding problems, which have been studied since the 1960s and were proven NP-complete in the generic case.
Sources: BIKE Specification, Appendix B.1.1 (Problems 3 and 4); NIST IR 8545 §§3.1–3.2 (BIKE depends on decisional QCSD and additionally QCCF).
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 = ): the specification's design target is DFR < 2−128. That is a target, not a proven bound: Wang, Wang and Wang (2023) construct a class of weak keys that puts a lower bound of about 2−117 on the average DFR (2−116.61, or 2−117.77 at 95% confidence), and use it for a key-recovery attack of cost 2116.61. ML-KEM-512's rate, for comparison, is 2−138.8 (FIPS 203, Table 1). None of these is a rate a browser tab could ever measure.
- 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
This browser model establishes a shared secret and uses AES-256-GCM to protect one message. A secure channel also needs a way to authenticate peers and handle replay. The next panel compares BIKE with 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 (target) | 2−138.8 | < 2−192 (target) | 2−164.8 | < 2−256 (target) | 2−174.8 |
| NIST Status | Round 4 — Not Selected | Standardized | Round 4 — Not Selected | Standardized | Round 4 — Not Selected | 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.
The two failure-rate columns are not the same kind of number. BIKE's are the specification's design targets, which no proof establishes: for Level 1, Wang, Wang and Wang, “Exploring Decryption Failures of BIKE: New Class of Weak Keys and Key Recovery Attacks” (2023), give a weak-key lower bound of 2−116.61 on the average rate, above the 2−128 target. ML-KEM's are the rates printed in FIPS 203, Table 1.
Visual: Public Key + Ciphertext Sizes
Physical faults are a separate attack model. Paiva et al., ePrint 2026/2492 (15 October 2026) report HQC/BIKE key recovery using valid ciphertexts and faults elsewhere in decapsulation, beyond the Fujisaki–Okamoto verification step, with laser experiments on an STM32H7. Protecting that check alone does not cover the whole fault surface; constant-time code does not itself prevent injected faults. This hardware result requires physical fault injection, not just changing a ciphertext. It is not a mathematical break of the code-based assumptions. This browser demo does not reproduce that attack or establish hardware fault resistance.
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, one of the two other code-based fourth-round candidates alongside HQC. BIKE has a non-zero decapsulation failure rate — but so does ML-KEM: FIPS 203 Table 1 gives ML-KEM-768 a decapsulation failure rate of 2−164.8. Neither scheme is perfectly correct. The difference is that ML-KEM's rate is computed from its own parameters, while BIKE's rests on a decoder analysis NIST IR 8545 judged less mature than HQC's.
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.
A breakthrough attack against lattice problems would not by itself break code-based schemes like HQC, BIKE, and Classic McEliece — or the other way round. That is the cryptographic diversity argument: diversification, not a guarantee, as SIKE showed. 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: Code-based diversity alongside ML-KEM — a role NIST's March 2025 selection of HQC now fills on the standards track, leaving BIKE a study design rather than a deployment option
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. Organizations with long-term security requirements may want a code-based scheme alongside it, so that a breakthrough against lattices would not compromise everything at once — but the standards-track code-based KEM is HQC (NIST IR 8545, March 2025), not BIKE, which has no NIST standardization path. And as SIKE showed, that is diversification, not a guarantee.
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