How two mathematicians created an equation that quietly runs the planet
April 14, 2026
7 min read
Add Us On GoogleAdd SciAm
How two mathematicians created an equation that quietly runs the planet
The Diffie-Hellman key exchange secures everything from your text messages to government secrets
By Jack Murtagh edited by Jeanna Bryner
Golden Sikorka/Getty Images
Love math? Sign up for our weekly newsletter Proof PositiveEnter your email
I agree my information will be processed in accordance with the Scientific American and Springer Nature Limited Privacy Policy. We leverage third party services to both verify and deliver email. By providing your email address, you also consent to having the email address shared with third parties for those purposes.
Sign Up
On October 30, 1942, a group of destroyer warships from the British Royal Navy hunted down a Nazi submarine near the Nile Delta. The warships pounded the submarine with underwater explosions until it floated to the surface, where it started filling with water and sinking. As its German crew scrambled to escape, three British heroes—Lieutenant Anthony Fasson, sailor Colin Grazier and 16-year-old canteen assistant Tommy Brown—did something that defied all instinct. They jumped from their ship onto the sinking vessel and climbed inside.
They were after the sub’s most valuable cargo: not weapons, not prisoners, but books. The pages contained codes for tuning the Nazi “Enigma machine” that allowed the German forces to communicate in secret. Deep inside the flooding commanding officers’ quarters, the men seized the volumes before the water-soluble ink dissolved into the sea. Only the teenager made it out alive. Less than two months later English mathematician Alan Turing’s team of code breakers used the codes to decipher Nazi messages, an effort estimated to have shortened the war by two years, saving millions of lives.
Cryptography is the math of communicating in secret, and it’s as high stakes as math gets. The submarine story and dozens more like it highlight a catch-22 that plagued cryptography for millennia: to speak in code, you must first agree on a code. If I want to send you a letter but distrust my mail carrier, I can encrypt my message with a cipher. Snoops won’t be able to read it, but neither will you. If I send a follow-up note explaining the cipher, the mail carrier can intercept that, too—we’re right back where we started. Called the key-distribution problem, this cryptography pitfall seems to imply that to establish a private communication channel, we effectively need privacy to begin with.
On supporting science journalism
If you're enjoying this article, consider supporting our award-winning journalism by subscribing. By purchasing a subscription you are helping to ensure the future of impactful stories about the discoveries and ideas shaping our world today.
This conundrum is why the history of cryptography reads less like a math textbook and more like a spy thriller. Lacking a mathematical solution to the key-distribution problem, the world relied on physical ones: clandestine meetings, armed couriers and occasional heists on sinking submarines. Then, in 1976, Stanford University researchers Whitfield Diffie and Martin Hellman proposed a solution that seemed to defy logic. Their method allowed two strangers to agree on a shared secret even when all their communications were out in the open for anybody to intercept and read. Their protocol, now known as Diffie-Hellman key exchange, has become a security workhorse of the modern Internet. Every time you check your bank balance, shop online, send a WhatsApp message or visit any “https” website, some version of Diffie-Hellman is probably securing the connection.
By the time of Diffie and Hellman, cryptographers knew how to encrypt documents by scrambling messages so they looked like gibberish to anyone who didn’t possess a secret key consisting of a large random number. So the objective for Diffie and Hellman’s scheme, including in present-day uses, is to generate a single large random number that only the sender and receiver know. With that number, they can use known methods to encrypt and decrypt messages.
Diffie-Hellman’s critical trick relies on a mathematical “one-way function,” an operation that is easy to perform but computationally infeasible to reverse. Consider Coca-Cola’s famously secret formula. Mixing ingredients is easy, but even with access to the finished product, chemists have trouble reconstructing a perfect copy of the beverage. Here’s how you and I can ensure that the secret chemical concoctions we cook up in our homes are identical to one another, assuming we are communicating only via mail with snooping postal workers inspecting our shipments:
- Public base: We agree on a common starting liquid, say, one liter of carbonated water mixed with a cola syrup. We announce this publicly, so eavesdroppers know the b