Key exchange: the client picks a random secret a and sends A = gᵃ mod p; the server picks a random secret b and sends B = gᵇ mod p. Each side then computes the same shared secret — K = Bᵃ mod p = Aᵇ mod p — without either secret ever crossing the network. This runs on real BigInt modular exponentiation in your browser.
Host key verification: a fresh Diffie–Hellman exchange by itself proves nothing about who is on the other end — an attacker sitting in the middle can run the same maths. SSH also authenticates the server's identity with a separate, persistent host key. This demo hashes that identity key with real SHA-256 to a fingerprint and colour swatch.
- Trust On First Use (TOFU): the very first time you connect, there is nothing to compare against, so the client saves the fingerprint it sees — trusting it blindly.
- Verified match: on every later connection, the client compares the presented fingerprint against the saved one. If they match, the server is who you think it is.
- Mismatch → MITM detected: an attacker relaying traffic can't reproduce the real server's private host key, so it must present a different fingerprint. A changed fingerprint on a known host is exactly the "REMOTE HOST IDENTIFICATION HAS CHANGED" warning real SSH clients print — and it blocks the connection before any session key is even negotiated.
K_client = B^a mod p
K_server = A^b mod p
K_client === K_server (proven live, never transmitted)
Simplification for clarity: real SSH uses separate algorithms for the host identity key (RSA/Ed25519) and the session key exchange (finite-field or elliptic-curve Diffie–Hellman); this demo uses the same modular-exponentiation group for both so the maths stays visible end to end.