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.

4 short lessons · about 16 minutes · 8 sources · updated November 2026

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

Before you readIn 2006 Italian police caught a Mafia boss partly by breaking his coded notes. What kind of code had he used?

Correct.Not quite. The answer is A form of Julius Caesar's cipher.

Bernardo Provenzano used a clumsy Caesar cipher, a method about as old as codes get. This lesson shows why it was so easy to break.

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.

Check yourselfA message in a Caesar cipher is intercepted. Why can an attacker read it without being told the key?

Correct.Not quite. The answer is There are only 25 shifts to try.

With so few keys, a brute force attack tries them all and keeps the one that reads as English. Caesar used three, but anyone can choose another shift.

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

  1. 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.

    Essentials · 4 min

  2. 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.

    Essentials · 4 min

  3. 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.

    Deeper · 4 min

  4. 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.

    Deeper · 4 min

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

  • Passwords, passkeys and account security

    See how passwords get stolen, how a passkey signs you in with nothing to steal, and why account recovery needs as much care as sign-in.

    4 lessons · 17 min

  • HTTPS and how a website proves who it is

    See what the padlock in your browser promises, what a website's certificate says, who vouches for it, and how a site gets one automatically.

    4 lessons · 24 min

  • Phishing and online scams

    Most online fraud starts with a message that gets someone to click, pay or hand over a code. See how scams pressure people in a hurry, how to check a message, and what to do in the first hour after a mistake.

    4 lessons · 16 min

  • How text becomes numbers

    Before a language model reads anything, the text is cut into tokens and each token becomes a point in a space where distance stands for meaning.

    4 lessons · 24 min

  • How recommendation feeds decide what you see

    Follow how a feed narrows billions of items to a screenful, what its score rewards, and how the design of a screen steers the choices you make.

    4 lessons · 17 min

  • What a database is

    See how tables, rows and keys organize records, how one SQL question pulls out an answer, why a spreadsheet stops being enough and when other kinds of database fit better.

    4 lessons · 16 min

All technology & computing topics · Take the quiz