{"id":51578760,"url":"https://github.com/systemslibrarian/crypto-lab-diffie-hellman-mitm","last_synced_at":"2026-07-11T03:32:24.781Z","repository":{"id":368079636,"uuid":"1283205140","full_name":"systemslibrarian/crypto-lab-diffie-hellman-mitm","owner":"systemslibrarian","description":null,"archived":false,"fork":false,"pushed_at":"2026-06-29T00:02:35.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-29T01:19:44.983Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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-28T16:59:38.000Z","updated_at":"2026-06-29T00:02:38.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/systemslibrarian/crypto-lab-diffie-hellman-mitm","commit_stats":null,"previous_names":["systemslibrarian/crypto-lab-diffie-hellman-mitm"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/systemslibrarian/crypto-lab-diffie-hellman-mitm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-diffie-hellman-mitm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-diffie-hellman-mitm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-diffie-hellman-mitm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-diffie-hellman-mitm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/systemslibrarian","download_url":"https://codeload.github.com/systemslibrarian/crypto-lab-diffie-hellman-mitm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-diffie-hellman-mitm/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":[],"created_at":"2026-07-11T03:32:24.701Z","updated_at":"2026-07-11T03:32:24.773Z","avatar_url":"https://github.com/systemslibrarian.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crypto-lab-diffie-hellman-mitm\n\n## What It Is\n\nAn interactive lesson on the **Diffie–Hellman key exchange** and the **man-in-the-middle attack** that breaks it when it is left unauthenticated. Diffie–Hellman solves a single problem: two parties who have never met agree on a shared secret over a channel anyone can read, using the hardness of the **discrete-logarithm problem** in the multiplicative group Z_p\\*. Its security model is precise and narrow — it defeats a *passive* eavesdropper, but it provides **no authentication**, so an *active* attacker who can modify messages can run two separate exchanges and sit in the middle. Every number in the demo is real, hand-rolled BigInt modular arithmetic (no faked math), and the discrete-log break and the ECDSA-signed fix both actually run in your browser. The toy primes exist only so the attack is fast enough to watch; this is a teaching tool, not a library.\n\n## When to Use It\n\n- **Teaching why \"secure key exchange\" needs authentication** — the demo shows the math is fine and the *protocol* is what fails, which is the point students most often miss.\n- **Explaining the passive-vs-active attacker distinction** — run the discrete-log break (passive, defeated at real sizes) right next to the MITM (active, defeated only by signatures) to make the contrast concrete.\n- **Briefing engineers before they touch a handshake** — make it visceral that raw, unauthenticated (EC)DH must be wrapped in signatures, certificates, or a PAKE.\n- **Showing the cost curve of discrete log** — the break runs in milliseconds on a 16-bit prime and is left disabled on a real 2048-bit group with a √p cost estimate, illustrating why bigger parameters stop the eavesdropper but never the man in the middle.\n- **Do NOT use it as a crypto library** — the primes are deliberately tiny and breakable, and rolling your own key exchange is exactly the mistake the lesson warns against. In production use a vetted implementation of an authenticated protocol (TLS 1.3, the Signal protocol, SSH, Noise).\n\n## Live Demo\n\n**[systemslibrarian.github.io/crypto-lab-diffie-hellman-mitm](https://systemslibrarian.github.io/crypto-lab-diffie-hellman-mitm/)**\n\nThe page is one scrollable lesson in five parts. You can run a Diffie–Hellman exchange on four parameter sets (`p = 23` up to a real 2048-bit RFC 3526 group), press **Break it** to recover Alice's secret exponent with a baby-step giant-step discrete-log attack, switch on **Mallory** to watch an active man-in-the-middle give Alice and Bob two different keys, and run a **real WebCrypto ECDSA** signed exchange that catches the tamper and fails closed. Controls: parameter preset, the private exponents `a` and `b`, Mallory's two exponents `m₁`/`m₂`, and honest-vs-tampered signed-delivery buttons.\n\n## How to Run Locally\n\n```bash\ngit clone https://github.com/systemslibrarian/crypto-lab-diffie-hellman-mitm\ncd crypto-lab-diffie-hellman-mitm\nnpm install\nnpm run dev\n```\n\nNo environment variables, no API keys, no backend — everything runs client-side in the browser. `npm run build` type-checks and produces the static `dist/`; `npm test` runs the engine unit tests; `npm run verify` does both.\n\n## Part of the Crypto-Lab Suite\n\n\u003e One of 60+ live browser demos at\n\u003e [systemslibrarian.github.io/crypto-lab](https://systemslibrarian.github.io/crypto-lab/)\n\u003e — spanning Atbash (600 BCE) through NIST FIPS 203/204/205 (2024).\n\n---\n\n*\"Whether you eat or drink, or whatever you do, do all to the glory of God.\" — 1 Corinthians 10:31*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemslibrarian%2Fcrypto-lab-diffie-hellman-mitm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsystemslibrarian%2Fcrypto-lab-diffie-hellman-mitm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemslibrarian%2Fcrypto-lab-diffie-hellman-mitm/lists"}