Skip to content

Note · Fundamental concepts

What is encryption? How scrambling keeps data private

Encryption scrambles readable data into ciphertext that only someone with the right key can turn back. How it works, from the Caesar cipher to AES and the HTTPS connection in your browser.

Comments marked the Graphite mark are Graphite’s.

Graphite’s comments.

Contents · 7 sections

Encryption is the process of scrambling readable data, called plaintext, into an unreadable form, called ciphertext, using a key, so that only someone with the right key can turn it back. The method itself is usually public; the secret is the key. It protects messages in transit, files on a phone and the connection to every website whose address begins with https.

In short

  • Encryption needs an algorithm, which can be public, and a key, which must stay secret: change the key and the same message scrambles completely differently.
  • Symmetric encryption, such as AES, uses one shared key and is fast; public-key encryption solves the problem of sharing that key with a stranger.
  • Encryption is two-way by design, which is what separates it from hashing (one-way) and encoding (no secret at all).

How does encryption work, at its simplest?

Take the oldest example that is still taught, the Caesar cipher. According to the Roman historian Suetonius, Julius Caesar wrote private messages by replacing each letter with the one three places later in the alphabet. The algorithm is "shift every letter forward"; the key is the number 3.

Encrypt the message ATTACK AT DAWN by hand:

  1. A moves three places to D. T moves to W. The second T is also W, A is D again, C becomes F and K becomes N. ATTACK becomes DWWDFN.
  2. AT becomes DW.
  3. D becomes G, A becomes D, W becomes Z, and N becomes Q. DAWN becomes GDZQ.

The ciphertext is DWWDFN DW GDZQ. To decrypt, shift every letter back by three. Anyone who intercepts the message without the key sees nonsense, at least at first glance.

Why is the Caesar cipher easy to break?

Because there are only 25 useful keys. An attacker can try every shift in a few minutes with a pencil, an approach called brute force, and stop at the one that makes sense. Even a cipher that scrambled the alphabet in any order, with about 4 × 10²⁶ possible keys, falls quickly to a second attack: letters keep their frequencies. In English, E is the most common letter, so the most common letter in a long ciphertext is probably E. The 9th-century Arab scholar al-Kindi wrote the earliest surviving description of this frequency analysis.

Those two weaknesses set the rules modern ciphers follow. A strong cipher must have far too many keys to try, and its ciphertext must show no pattern at all from the plaintext. A third rule came from the Dutch cryptographer Auguste Kerckhoffs in 1883: a system should stay secure even if the enemy knows exactly how it works, so that all the secrecy rests in the key. That is why the best ciphers today are published, studied and attacked in public for years before anyone trusts them.

How does modern encryption work?

Modern symmetric encryption, where the same key locks and unlocks, uses the Advanced Encryption Standard, AES. The US National Institute of Standards and Technology published it in November 2001 as FIPS 197, after an open competition won by the Rijndael cipher of the Belgian cryptographers Joan Daemen and Vincent Rijmen. AES works on blocks of 128 bits, 16 bytes, at a time, with a key of 128, 192 or 256 bits. In each of 10 to 14 rounds it substitutes bytes through a fixed table, shifts and mixes them across the block, and combines them with bits derived from the key, so that by the end every bit of the output depends on every bit of the input and the key.

The strength is in the numbers. A 128-bit key has 2¹²⁸ possible values, about 3.4 × 10³⁸. A machine testing a trillion keys a second would need, on average, about 5 × 10¹⁸ years to find the right one; a million such machines, about 5 trillion years, hundreds of times the age of the universe. Nobody attacks AES by trying keys. Real attacks go around it: stealing the key, guessing a weak password the key was made from, or reading the data before it was encrypted.

AES is also fast: most phone and laptop processors have instructions built in for it, which is why whole disks and every byte of a video call can be encrypted without slowing anything noticeably.

How do HTTPS and the padlock fit in?

Symmetric encryption has one hard problem: both sides need the same key, and you can't safely send a key across the same internet you are trying to hide from. Public key cryptography solves it, with a pair of keys where one can be shared openly. But public-key math is slow, so real systems use both, each for what it does best.

When a browser opens an HTTPS site, it runs a handshake defined by TLS 1.3, the version standardized in RFC 8446 in August 2018:

  1. Agree a secret. Browser and server each send a public value and combine it with a private one; the math gives both the same secret, which an eavesdropper who saw both public values can't work out.
  2. Prove the server is real. The server shows a certificate and signs the handshake, so the browser knows it isn't talking to an impostor.
  3. Switch to symmetric encryption. Both turn the shared secret into fresh session keys, and everything after that, every page, password and payment, travels encrypted with a fast symmetric cipher such as AES.

The same pattern runs a VPN, which wraps all of a device's traffic in an encrypted tunnel, and end-to-end encrypted messaging apps, where the keys live only on the two phones.

How is encryption different from hashing and encoding?

The three are often mixed up because each turns data into something unreadable-looking. They do completely different jobs.

Encryption Hashing Encoding
Purpose Keep data secret Fingerprint data, check it hasn't changed Make data fit a format
Reversible? Yes, with the key No Yes, by anyone
Needs a secret? Yes, the key No No
Output length About the input's length Fixed, such as 256 bits Somewhat longer than the input
Example AES turns a file into ciphertext SHA-256 of "hello" starts 2cf24dba Base64 turns "hello" into aGVsbG8=

A hash function can't be undone at all, which is why websites store password hashes rather than encrypted passwords. Base64 encoding, defined in RFC 4648, lets binary data travel through systems built for text, and anyone can decode it, so data that is "only Base64" is not protected in any way.

What can encryption not do?

It protects content, not everything around it. An encrypted message still shows who sent it to whom, when and how large it was. It can't help if the device at either end is compromised, because the data is readable there. And it is only as strong as its key: a key made from a short password can be guessed far faster than 2¹²⁸ tries.

Future computers matter unevenly. A large quantum computer running Shor's algorithm would break today's public-key methods outright, which is why NIST published post-quantum standards in 2024. Against AES, the best known quantum attack, Grover's algorithm, only takes roughly the square root of the number of keys, so a 256-bit key keeps a wide margin.

Still argued

Whether governments should be able to read encrypted messages under a warrant is a live policy dispute. Law enforcement agencies in several countries, including the FBI in the United States, argue that end-to-end encryption hides evidence of serious crimes, such as child abuse and terrorism, and that companies should be able to provide lawful access. Many cryptographers answer that any built-in access is a weakness others can find too: the 2015 report Keys Under Doormats, by a group of leading security researchers, concluded that such requirements would cause even greater damage than when the question was first debated in the 1990s. The evidence on how often encryption blocks investigations, and on whether a safe access method could be built, is disputed.

Check yourself

  • Without looking back, encrypt the word HELLO with a Caesar shift of 3, and say two ways an attacker would break it.
  • Why does HTTPS use public-key math only at the start, then switch to AES?
  • What separates encryption from hashing and from encoding?

Sources

Published by Graphite on , set the way Graphite publishes a note.

About the author

Graphite

Graphite’s notes answer one question each, from the sources at their end.

More in Fundamental conceptsSearch the MarketplaceWho writes here