Technology & Computing · Cybersecurity & privacy
How encryption works
Encryption scrambles a message so only someone with the right key can read it. See how a shared key works, how strangers agree on one in public, and what end-to-end encryption in a chat app promises.

What you will learn
- Explain how a cipher uses a key to scramble a message, and how a Caesar shift is broken
- Explain why a good cipher stays secure even when everything but the key is public
- Explain how Diffie-Hellman key exchange creates a shared key over a public channel
- Describe how public-key encryption uses a public key to lock and a private key to unlock
Lesson 1 of 4 · 4 min
Why a cipher's secret is its key
In April 2006, Italian police caught the Mafia boss Bernardo Provenzano in Sicily. Part of what gave him away was his coded notes. They used a clumsy version of a cipher named after Julius Caesar, and investigators broke it.
A cipher is a method for scrambling a message, and the key is the setting that controls it. Caesar's method shifts every letter a fixed number of places along the alphabet. The Roman historian Suetonius says Caesar used a shift of three, so A becomes D and B becomes E.
The readable message is the plaintext, and the scrambled one is the ciphertext. Anyone who knows the key just shifts back. In English there are only 25 possible shifts, so an attacker can try every one and keep the one that makes sense. That's a brute force attack.
There's a second weakness. In English, some letters, like E, turn up far more often than others, and a shift keeps that pattern. Counting letters to break a cipher is frequency analysis. The first known explanation of it was written in the 9th century by the Arab scholar al-Kindi.
In 1883 the Dutch cryptographer Auguste Kerckhoffs, who taught in Paris, published rules for military ciphers. One became a founding idea. A cipher should stay secure even if everything except the key is public. Claude Shannon later put it as "the enemy knows the system."
The reason is practical. Something as large as a whole cipher design can't count on staying secret for long. A key is small, and you can change it. If only the key must stay hidden, keeping secrets becomes a matter of guarding keys.
Today's standard cipher, AES, follows that rule. The US standards agency NIST adopted it in 2001 after a public five-year process that weighed fifteen designs. Anyone can read how it works. It uses one key to both lock and unlock, and that key is 128, 192 or 256 bits long.
That key length shuts out brute force. Say a 2019 supercomputer tested 100 trillion AES keys a second. Trying every 256-bit key would still take a number of years 56 digits long.
Try to recallWhy do cryptographers want a cipher to stay secure even when everything but the key is public?
A whole cipher design can't be kept secret for long, but a key is small and easy to change. If security rests only on the key, a leaked design does no harm. This is Kerckhoffs's principle, "the enemy knows the system."
A cipher scrambles plaintext under the control of a key. Caesar's shift falls to brute force and letter counting. Modern ciphers like AES publish their design and rely on keys too numerous to try.
Lessons in this topic
Why a cipher's secret is its key
Start with Julius Caesar's letter shift, see the two ways it breaks, and learn why modern ciphers publish everything except the key.
How two strangers agree on a secret in public
See how two people who have never met can build a shared key over an open line, and how one key can lock what only another opens.
What end-to-end encryption hides, and what it doesn't
See what a chat app can and can't read when messages are end-to-end encrypted, and how your phone and backups can still expose them.
The fight over police access and the quantum deadline
See both sides of the dispute over police access to encrypted messages, and why the world is replacing the math behind public keys.
Three quick stories from this topic
The first codebreaking manual
The first known explanation of codebreaking was written in the 9th century
The Arab scholar al-Kindi described frequency analysis in A Manuscript on Deciphering Cryptographic Messages. Common letters stay common after a simple substitution, so counting them gives the key away.
Counting letters
In English, E turns up more than any other letter. A Caesar-shifted message keeps that pattern, just moved along the alphabet.
Why keys got bigger
Modern ciphers such as AES use keys up to 256 bits long, far too many to try one by one.
Public keys, invented in secret
British intelligence worked out public-key encryption years before it was published
Mathematicians at GCHQ, Britain's signals intelligence agency, showed how public-key cryptography could work by 1969. Clifford Cocks devised an RSA-like system in 1973. The work stayed secret until 1997.
The public version
Diffie and Hellman published key exchange in 1976, and Rivest, Shamir and Adleman published RSA in 1977.
Why it mattered
Before public keys, two parties had to send a secret key by courier or mail before they could talk securely.
A shrinking quantum threat estimate
Breaking RSA may need under a million qubits, less than a twentieth of the 2019 estimate
Craig Gidney estimated that a quantum computer with under a million noisy qubits could factor a 2048-bit RSA number in under a week. His 2019 estimate with a colleague needed 20 million.
Not built yet
Lab runs of Shor's algorithm have only factored small numbers, starting with 15 in 2001.
Why it matters now
Data recorded today could be decrypted later. NIST finalized three post-quantum standards in August 2024.
Sources
- Caesar cipher, Wikipedia
- Frequency analysis, Wikipedia
- Kerckhoffs's principle, Wikipedia
- Advanced Encryption Standard, Wikipedia
- Brute-force attack, Wikipedia
- Diffie-Hellman key exchange, Wikipedia
- RSA cryptosystem, Wikipedia
- How to factor 2048 bit RSA integers with less than a million noisy qubits, Craig Gidney, arXiv, 2025





