← All animations

🔐 Public-Key Crypto

How can two strangers agree on a secret while everyone is listening? And how can you receive a private message from someone you've never met? Public-key cryptography answers both with a beautiful trick: some operations are easy to do but hard to undo. Below, mix paints to share a secret in plain sight, watch a public padlock lock a box only its owner can open, and run a tiny real RSA round-trip.

1. Sharing a secret in the open — the paint-mixing trick

Alice and Bob want a shared secret colour, but everything they send travels past Eve. They agree publicly on a common paint. Each privately picks a secret paint and mixes it with the common one. They swap the mixtures in the open, then stir in their own secret again. Because mixing order doesn't matter, both pots end up the same colour — yet Eve, holding only the two public mixtures, can't un-stir them to recover that colour. Pick the secrets and press Mix & exchange.

Pick two secret paints, then mix.
The common paint is public, and so are both mixtures Eve sees. Recovering a secret from a mixture means "un-mixing" paint — practically impossible. In real DH the paint is modular exponentiation (gx mod p); un-mixing is the hard discrete-log problem.

2. The open padlock — public-key encryption & a real RSA round-trip

Imagine handing out open padlocks to the whole world while keeping the only key for yourself. Anyone can lock a box shut with your padlock, but only your key opens it — so anyone can send you a private message, and no one but you can read it. That's a public key (the padlock) and a private key (the key). Press Send locked box to watch one travel past an eavesdropper.

Bob's padlock is public; only Bob holds the key.

Under the hood it's arithmetic. With real (tiny) RSA numbers, locking is me mod n and unlocking is cd mod n. The catch: finding the private d needs the prime factors of n — easy to multiply, brutally hard to factor when the primes are huge. Type a message number and watch it survive the round-trip.

m = 42

3. Why this matters — symmetric vs asymmetric, HTTPS & signatures

Two flavours of crypto, and the problem that links them:

The one-way idea behind all of it: multiplying two primes (or exponentiating mod p) is cheap; reversing it — factoring, or the discrete log — is so costly that with big enough numbers it would take longer than the age of the universe. Security rests on that gap.