Learn › Part 3 ยท Cryptography and secure protocols

Symmetric cryptography and classical ciphers

Terminology, Kerckhoffs' principle, attack models, perfect secrecy, additive, multiplicative and affine ciphers, transposition, and stream versus block ciphers.

Terms and principles

  • Symmetric cipher: one shared key; C = Ek(P), P = Dk(C), with Dk(Ek(x)) = x. A cryptosystem is the 5-tuple (P, C, K, E, D).
  • Cryptanalysis recovers plaintext or keys without knowledge of the key; cryptology = cryptography + cryptanalysis.
  • Kerckhoffs' principle: everything except the key is public, so a leaked key can simply be replaced.
  • Key sizes: 56-bit DES fell to brute force; AES-128/192/256 use 10/12/14 rounds. Grover's algorithm roughly halves symmetric security (AES-128 → about 264), so AES-256 is the long-term choice.
Attack modelAttacker has
Ciphertext-onlyCiphertexts
Known-plaintextSome plaintext-ciphertext pairs it did not choose
Chosen-plaintextAn encryption oracle
Chosen-ciphertextA decryption oracle (strongest)

Perfect secrecy and the one-time pad

Shannon: perfect secrecy means seeing the ciphertext does not change the odds of any plaintext. It requires a truly random key at least as long as the message (|K| ≥ |M|) used once. Reuse leaks: c1 ⊕ c2 = m1 ⊕ m2. Stream ciphers approximate the pad by expanding a short key with a generator.

Substitution ciphers over Z26 (a = 0 … z = 25)

CipherEncryptDecryptKeys
Additive (shift; Caesar k = 3)(P + k) mod 26(C − k) mod 2626 (25 useful)
Multiplicative(P × k) mod 26(C × k−1) mod 2612: k with gcd(k, 26) = 1
Affine(P × k1 + k2) mod 26((C − k2) × k1−1) mod 2612 × 26 = 312
Random monoalphabeticTable lookupInverse table26! ≈ 288

Valid multiplicative keys: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25. Inverses: 3↔9, 5↔21, 7↔15, 11↔19, 17↔23, 25↔25.

Worked examples

  • Additive, k = 20: l (11) → 31 mod 26 = 5 = F; back: 5 − 20 = −15 → −15 + 26 = 11 = l.
  • Affine, k1 = 5, k2 = 8: h (7) → 7 × 5 + 8 = 43 mod 26 = 17 = R.

Every monoalphabetic cipher keeps letter frequencies (E ≈ 12.7%, T ≈ 9.1%, A ≈ 8.2%), so frequency analysis breaks even the 26! table. Polyalphabetic ciphers such as Vigenère and Hill flatten frequencies.

Transposition ciphers

Characters stay the same; positions change.

  • Keyless columnar: write “meet me at the park” in rows of four (meet / meat / thep / arkz) and read by columns: MMTA EEHR EAEK TTPZ.
  • Keyed block permutation: key [3 1 4 5 2] means output positions take input characters 3, 1, 4, 5, 2. “enemy” → EEMYN. Decrypt with the inverse [2 5 1 3 4].
  • Combining both (rows, then permuted columns) gives “ETTHEAKIMAOTYCNZNTSG” for “enemy attacks tonight”.

Stream versus block

Stream ciphers (RC4, ChaCha20, LFSR-based) encrypt symbol by symbol with a keystream; block ciphers (DES 64-bit blocks, AES 128-bit blocks) encrypt fixed blocks and pad the last one (for example PKCS#7).

The two-padlock puzzle

Alice locks a box and sends it; Bob adds his lock and returns it; Alice removes hers and sends it back; Bob opens it. This needs locks that commute without leaking: XOR fails, because XORing the three transcripts gives M.

Common pitfalls

  • Wrap negatives by adding 26.
  • Multiply by the inverse to decrypt, not by the key.
  • A large key space does not stop frequency analysis.