The most beautiful algorithm in computer science.

If you don't recognize it, this is Diffie-Hellman.
Diffie-Hellman is an algorithm that lets two parties establish a secret over an insecure network.
This is useful when:
The math behind it is surprisingly simple:
A = g^a mod p, and sends A to BobB = g^b mod p, and sends B to AliceThen:
s = B^a mod ps = A^b mod pWhen that is done, both get the same s (the shared secret), because: g^(a * b) mod p = g^(b * a) mod p
This works because it relies on one-way mathematical functions—easy to compute in one direction, but hard to reverse in the other.
Put differently, if an attacker sees g, p, A, and B, it still can't compute s when p is a large enough prime.
I remember learning about this in school with the analogy of mixing paints and it completely blew my mind.