← back to cryptography

Symmetric Ciphers

Wikipedia · wpSymmetric-key algorithm · CC BY-SA 4.0

A symmetric cipher uses the same key to encrypt and decrypt. The sender and receiver must both know the secret. Every cipher in this chapter is breakable by modern standards, but they introduce the core idea: transform plaintext into ciphertext using a shared secret, and reverse the transformation with the same secret.

plain encrypt key cipher decrypt key plain Same key encrypts and decrypts.

XOR cipher — the simplest encryption

XOR each byte of the plaintext with a key byte. XOR again with the same key to decrypt. It is its own inverse: a XOR k XOR k = a. With a truly random key as long as the message (used once), this is the wpone-time pad, which is information-theoretically secure. With a short repeating key, it is trivially breakable.

Scheme

Caesar cipher — shift by a fixed amount

Replace each letter with the letter k positions later in the alphabet (wrapping around). The key is a single number from 0 to 25. Only 26 possible keys: brute force takes 26 tries. Caesar reportedly used k=3.

Scheme

Substitution cipher — arbitrary permutation

Map each letter to a different letter via a permutation of the alphabet. The keyspace is 26! (about 4 x 1026), far too large to brute-force. But letter frequency analysis breaks it: English has known frequencies (E is the most common), and the cipher preserves those frequencies.

Scheme

Keyspace size

The security of a cipher depends on how many keys an attacker must try. Caesar: 26 keys. Substitution: 26! keys. XOR with a 1-byte key: 256 keys. XOR with a 128-bit key: 2128 keys.

Modern ciphers aim for keyspaces so large that brute force is physically impossible.

Scheme
Neighbors

Cross-references

Foundations (Wikipedia)