{"id":51578780,"url":"https://github.com/systemslibrarian/crypto-lab-e91","last_synced_at":"2026-07-11T03:32:25.611Z","repository":{"id":367851367,"uuid":"1263888185","full_name":"systemslibrarian/crypto-lab-e91","owner":"systemslibrarian","description":"Browser-based E91 QKD demo — entangled-pair measurements, CHSH Bell test, key from aligned bases. |S|≈2.83 means secure; an eavesdropper drags it below 2 and is caught. Ekert's entanglement-based answer to BB84","archived":false,"fork":false,"pushed_at":"2026-06-28T02:02:37.000Z","size":75,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-28T02:18:29.358Z","etag":null,"topics":["bell-inequality","browser-demo","chsh","crypto-lab","e91","ekert","entanglement","qkd","quantum-cryptography","quantum-key-distribution"],"latest_commit_sha":null,"homepage":"https://systemslibrarian.github.io/crypto-lab-e91/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/systemslibrarian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-09T11:07:24.000Z","updated_at":"2026-06-28T02:02:41.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/systemslibrarian/crypto-lab-e91","commit_stats":null,"previous_names":["systemslibrarian/crypto-lab-e91"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/systemslibrarian/crypto-lab-e91","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-e91","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-e91/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-e91/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-e91/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/systemslibrarian","download_url":"https://codeload.github.com/systemslibrarian/crypto-lab-e91/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-e91/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35350133,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-11T02:00:05.354Z","response_time":104,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bell-inequality","browser-demo","chsh","crypto-lab","e91","ekert","entanglement","qkd","quantum-cryptography","quantum-key-distribution"],"created_at":"2026-07-11T03:32:25.501Z","updated_at":"2026-07-11T03:32:25.599Z","avatar_url":"https://github.com/systemslibrarian.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crypto-lab-e91\n\n## What It Is\n\nAn interactive simulation of **E91 (Ekert 1991)**, the entanglement-based quantum key distribution protocol. A source emits polarization-entangled photon pairs in the singlet state; Alice and Bob each measure their half at independently chosen analyzer angles; the joint statistics are checked against the **CHSH form of Bell's inequality**. Quantum mechanics allows |S| to reach the **Tsirelson bound 2√2 ≈ 2.828**, while any classical (local hidden-variable) theory is stuck at |S| ≤ 2. An intercept-resend eavesdropper destroys the entanglement and collapses S back into the classical regime — that is the eavesdropper alarm.\n\nThe protocol is the cousin of BB84 in the sibling [`crypto-lab-bb84`](https://systemslibrarian.github.io/crypto-lab-bb84/) demo, but it leans on a fundamentally different security argument: **Bell-inequality violation, not no-cloning**. The engine is implemented from scratch in TypeScript using the standard textbook quantum-mechanical predictions for the singlet state, plus three additional channel models (depolarizing noise, analyzer misalignment, photon loss) so the demo can show **that a missing 2√2 is not by itself proof of an eavesdropper** — noise and calibration error can produce the same signature.\n\nThis is an **idealized educational simulation**, not a model of real photon-counting hardware. There is no detector dark-count model, no finite-key correction, no decoy-state analysis, no side-channel attacks. The math you see is the standard textbook math, decorated with sample-size-aware statistics (per-correlation standard errors and a 95% CI on |S|) so the security verdict depends on the data rather than a hard-coded threshold.\n\n## When to Use It\n\n- **Teaching how entanglement detects eavesdroppers** — the singlet's correlation exceeds anything a classical theory can produce, and Eve's measurement drags it back to classical.\n- **Showing why E91 ≠ BB84** — same problem, different physics. BB84's alarm is QBER from Heisenberg disturbance; E91's alarm is a missing 2√2 from broken entanglement.\n- **Introducing CHSH, Tsirelson's bound, and Bell-test statistics** — including the lesson that the answer is a confidence interval, not a single number.\n- **Distinguishing attack from ordinary degradation** — the noisy, misaligned, and lossy scenarios produce reduced |S| for benign reasons; the demo makes this explicit instead of pretending |S| \u003c 2 always means \"Eve.\"\n- **Setting up device-independent QKD intuition** — DI-QKD descends directly from E91; the same Bell-test-as-security-certificate idea drives loophole-free Bell experiments and entanglement-based satellite QKD.\n- **Do NOT** use this as a model of a real quantum channel. It is faithful to the textbook idealization, not to lab hardware.\n- **Do NOT** confuse QKD with post-quantum cryptography. QKD addresses *key distribution* over a quantum channel; it does not replace the larger PQC migration story (see the rest of the suite for that).\n\n## Live Demo\n\n**[systemslibrarian.github.io/crypto-lab-e91](https://systemslibrarian.github.io/crypto-lab-e91/)**\n\nInside the page:\n\n- **Scenario chip strip** — five channel models you can flip between: ideal, intercept-resend Eve, depolarizing noise, misaligned analyzer, lossy channel. Each scenario has a one-line story and an expectation for |S| and key agreement; the parameterised ones (noise level, misalignment angle, detection efficiency) expose a slider.\n- **Statistical verdict panel** — secure / compromised / inconclusive, with the 95% CI for |S| spelled out.\n- **CHSH gauge with confidence band** — visual marker for the measured |S|, dashed CI box, and labelled ticks at the classical bound (2) and Tsirelson's bound (2√2).\n- **Expected vs measured correlation table** — the four E(aᵢ,bⱼ) with their theoretical value, measured value, 95% CI, standard error, and sample size. A `!` badge appears on rows more than 3σ from expected.\n- **Sifted key panel** — Alice / Bob bit strings, per-bit agreement coloring, measured vs expected agreement percentage.\n- **Round-by-round transcript (optional)** — first 50 rounds with bucket (CHSH / key), analyzer indices, angles in degrees, ±1 outcomes, and the product A·B.\n- **The Bell test explained** — concept cards, the singlet correlation curve E(Δ) = −cos(2Δ) with CHSH points marked, and the five-step protocol flow.\n- **E91 vs BB84** — six-row comparison table linking the sibling demo.\n- **In the real world** — Bell (1964), Aspect (1982), Ekert (1991), loophole-free Bell (2015), Micius (2017), device-independent QKD (2022).\n- **Sources \u0026 further reading** — primary references with DOIs, plus a \"what this simulation does and does not model\" caveat box.\n\n**Shareable runs**: the rounds, scenario, scenario knob value, seed, and transcript flag are mirrored to the URL hash. The \"Copy link to this run\" button gives you a deterministic URL that reproduces the exact run; \"Copy results (CSV)\" exports the summary and transcript to clipboard.\n\n## What Can Go Wrong\n\n- **A missing 2√2 is ambiguous.** A measured |S| below the classical bound can be caused by an eavesdropper *or* by ordinary noise, misalignment, or loss; from |S| alone you cannot tell which, so a degraded key is discarded either way.\n- **Finite-key effects.** Real E91 needs finite-key security corrections and enough rounds for the CI to tighten; a small sample can leave the verdict inconclusive or misleading (this demo models the statistics but not full finite-key proofs).\n- **Detector side-channels (real hardware).** Physical implementations face detector-blinding, timing, and efficiency-loophole attacks that an idealized simulation does not capture.\n- **Unauthenticated classical channel.** The public discussion/sifting channel must be authenticated; without it, a man-in-the-middle can defeat QKD regardless of the Bell test.\n- **The detection-efficiency (loss) loophole.** Low detection efficiency can let a local hidden-variable model fake a Bell violation, so loss must be accounted for in any real security claim.\n\n## Real-World Usage\n\n- **Device-independent QKD.** E91 is the conceptual ancestor of DI-QKD, where security is certified by an observed Bell-inequality violation rather than trust in the devices.\n- **Entanglement-based QKD experiments.** Laboratory and field demonstrations distribute entangled photon pairs and verify CHSH violation as the security test.\n- **Satellite QKD.** The Micius satellite distributed entangled photons over ~1200 km, demonstrating entanglement-based key distribution at intercontinental scale.\n- **Loophole-free Bell tests.** Experiments such as Hensen et al. (2015) closed the detection and locality loopholes, underpinning the security argument E91 relies on.\n- **Bell-test-certified randomness.** The same Bell-violation certificate used in E91 is used to certify randomness in device-independent randomness expansion.\n\n## How to Run Locally\n\n```bash\ngit clone https://github.com/systemslibrarian/crypto-lab-e91\ncd crypto-lab-e91\nnpm install\nnpm run dev\n```\n\n## Related Demos\n\n- [crypto-lab-bb84](https://systemslibrarian.github.io/crypto-lab-bb84/) — the sibling QKD protocol whose alarm is QBER from no-cloning, not a Bell violation.\n- [crypto-lab-shor](https://systemslibrarian.github.io/crypto-lab-shor/) — Shor's algorithm, the quantum attack that motivates quantum-safe key distribution.\n- [crypto-lab-grover](https://systemslibrarian.github.io/crypto-lab-grover/) — Grover's algorithm and quantum search against symmetric keys.\n- [crypto-lab-pq-families](https://systemslibrarian.github.io/crypto-lab-pq-families/) — the five post-quantum families, the computational alternative to QKD.\n\n## Statistical interpretation of S\n\nThe CHSH parameter `S = E(a₁,b₁) + E(a₁,b₂) + E(a₂,b₁) − E(a₂,b₂)` is computed from four sample means, each over its own subset of rounds. Each `E(aᵢ,bⱼ)` has standard error `SE = √((1 − E²)/n)`; the four are independent, so `Var(S)` is the sum of variances, and `SE(S) = √Σ SE(Eᵢⱼ)²`. The 95% confidence interval is `|S| ± 1.96·SE(S)`.\n\nThe simulator's verdict is **based on where the |S| CI falls relative to the classical bound of 2**, not on a fixed threshold:\n\n- `secure` — the entire 95% CI for |S| is above 2; the result is statistically inconsistent with any local hidden-variable model.\n- `compromised` — the entire 95% CI is below 2; the Bell violation has been lost. (Could be Eve; could be sufficiently strong noise or misalignment. From |S| alone you cannot tell which, so the key is discarded either way.)\n- `inconclusive` — the CI straddles 2. Run more rounds.\n\nThis is why the demo exposes a \"rounds\" knob and a \"lossy channel\" scenario: you can watch a borderline case sit in the inconclusive region until enough data tightens the CI.\n\n## Testing\n\n`scripts/engine.test.mjs` is the source of truth. It covers:\n\n- The singlet correlation function returns textbook values.\n- The theoretical S for each scenario matches the textbook closed form (`2√2`, `√2` under intercept-resend at π/8, `(1−p)·2√2` under depolarizing noise, `2√2·cos(2δ)` under misalignment, and unchanged under loss).\n- The theoretical key agreement at aligned bases matches its closed form per scenario.\n- `runE91` converges to the predicted |S| within 0.05 for 30k seeded rounds across all five scenarios.\n- The confidence-aware verdict classifies seeded runs as `secure` / `compromised` correctly, and the legacy `eve: true / false` flag still selects the right scenario.\n- The transcript respects its cap, labels CHSH vs key buckets, and records consistent product = A·B.\n- Per-correlation standard errors and the S CI are populated and bracket the measured value.\n- `effectiveRounds` for the lossy channel matches `rounds · η²` to within sampling noise.\n- `resolveScenario` accepts both ID strings and partial-override objects.\n\nCI (`.github/workflows/ci.yml`) runs `npm run build \u0026\u0026 npm test` on every push and PR. The deploy workflow (`.github/workflows/deploy.yml`) ships `dist/` to GitHub Pages on push to `main`.\n\n## Sources\n\nPrimary references are also listed on the live page with DOIs. The most load-bearing:\n\n- J. S. Bell. *On the Einstein Podolsky Rosen paradox.* Physics 1, 195 (1964).\n- J. F. Clauser, M. A. Horne, A. Shimony, R. A. Holt. *Proposed experiment to test local hidden-variable theories.* PRL 23, 880 (1969).\n- B. S. Cirel'son. *Quantum generalizations of Bell's inequality.* Lett. Math. Phys. 4, 93 (1980).\n- A. K. Ekert. *Quantum cryptography based on Bell's theorem.* PRL 67, 661 (1991).\n- B. Hensen et al. *Loophole-free Bell inequality violation.* Nature 526, 682 (2015).\n- J. Yin et al. *Satellite-based entanglement distribution over 1200 km.* Science 356, 1140 (2017).\n- D. P. Nadlinger et al. *Experimental QKD certified by Bell's theorem.* Nature 607, 682 (2022).\n- W. Zhang et al. *A device-independent QKD system for distant users.* Nature 607, 687 (2022).\n\nStandard textbook treatment: Nielsen \u0026 Chuang, *Quantum Computation and Quantum Information* (Cambridge), Chapters 2 and 12. For QKD security proofs beyond the idealization, see Renner's 2005 thesis [`arxiv.org/abs/quant-ph/0512258`](https://arxiv.org/abs/quant-ph/0512258).\n\n---\n\n*One of 120+ browser demos in the [Crypto Lab](https://crypto-lab.systemslibrarian.dev/) suite.*\n\n*\"So whether you eat or drink or whatever you do, do it all for the glory of God.\" — 1 Corinthians 10:31*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemslibrarian%2Fcrypto-lab-e91","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsystemslibrarian%2Fcrypto-lab-e91","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemslibrarian%2Fcrypto-lab-e91/lists"}