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.
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.
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.
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.
Two flavours of crypto, and the problem that links them: