Cryptography / Symmetric encryption

Symmetric encryption

One secret key scrambles a message and the same key brings it back. Seven steps: a real AES example, the problem of sharing the key, and the two families of cipher.

Beginner7 steps~6 min
Alice — sends the message
Bob — receives it, holds the same key
Key K — the one shared secret
Eve — sees everything on the wire
// THE SHORT VERSION

In 30 seconds

In symmetric encryption the sender and the receiver share one secret key. The same key turns a readable message into noise and turns the noise back into the message.

It is very fast, which is why nearly all data is encrypted this way, using ciphers such as AES (works on 16-byte blocks) or ChaCha20 (works on a stream of bytes).

Its weak point is getting the key to both sides without anyone else seeing it. That is usually solved with public-key methods, used only to agree on the key.

Symmetric encryption, step by step

STEPS01 / 07

Step 2 shows AES on a single block with no mode, to keep it small. Real systems use an authenticated mode such as AES-GCM or ChaCha20-Poly1305, which also detects tampering.

STEP 01 / 07 One key, both directions
THE MATH
c = Encrypt(K, m) m = Decrypt(K, c)
  1. Step 1: One key, both directions. Alice and Bob each hold a copy of the same secret key K. Whatever K scrambles, K unscrambles: that is what symmetric means. Anyone without K sees only noise.
  2. Step 2: Alice encrypts. Alice feeds her message and K into a cipher, here AES. Out comes ciphertext: 16 bytes that look random. Change one bit of the key or the message and the output changes completely.
  3. Step 3: Bob decrypts. Bob runs the same cipher backwards with his copy of K and the message reappears. Eve, who copied the ciphertext on the way, has the same bytes but no key, so she learns nothing but its length.
  4. Step 4: The key distribution problem. Before any of this works, Alice and Bob must both have K, and it cannot simply be sent: whoever sees the key in transit can read everything. Every pair of people also needs its own key, so the number of keys grows fast.
  5. Step 5: Why bother: speed. Symmetric ciphers are built from cheap operations: XOR, table lookups, shifts and additions. A modern processor encrypts gigabytes per second with AES or ChaCha20, hundreds to thousands of times faster than RSA. So real systems use slow public-key maths once, to agree on K, then switch.
  6. Step 6: Block ciphers: AES. A block cipher scrambles a fixed-size chunk. AES always takes 16 bytes, so a longer message is cut into 16-byte blocks. A mode of operation, such as CBC or GCM, says how to handle many blocks so that equal blocks of plaintext do not produce equal blocks of ciphertext.
  7. Step 7: Stream ciphers: ChaCha20. A stream cipher instead stretches a key into a long run of random-looking bytes, the keystream, and combines one keystream byte with each message byte using XOR. No blocks and no padding. ChaCha20 is the common one; with AES it protects most web traffic today.
VALUES SO FAR
K128-bit keysecret
m····Alice
c····public
keys····problem
speed····AES
block····AES
stream····ChaCha20
// BEFORE

Learn this first

Nothing. This concept starts from scratch.

Spotted a mistake on this page?