Classical Cryptography

Lecture 23
→ next · ← back · F fullscreen

Shift and affine ciphers

Shift cipher

Encryption:  Ek(p) ≡ p + k (mod 26)
Decryption:  Dk(c) ≡ c − k (mod 26)

p = plaintext letter,  c = ciphertext letter,  k = key

Caesar used k = 3:  ATTACK AT DAWN → DWWDFN DW GDZQ

Shift cipher

Message   k =  

→

Affine cipher

Encryption:  Ea,b(p) ≡ ap + b (mod 26)
Decryption:  Da,b(c) ≡ a−1(c − b) (mod 26)

key (a, b):  gcd(a, 26) = 1 so that a−1 exists,  0 ≤ b ≤ 25

(a, b) = (5, 8):  ATTACK AT DAWN → IZZISG IZ XIOV

Affine cipher

Message   a   b  

→

Brute-forcing the key

26
shift keys
312
affine keys (12 × 26)

Substitution ciphers

Substitution cipher

The key is any rearrangement of the alphabet. Click two cipher letters to swap them.

26! ≈ 4 × 1026 keys

At 109 keys per second, trying them all takes ≈ 1.3 × 1010 years — about the age of the universe.

Frequency analysis

Breaking a substitution cipher

cipher letter · count → guess

English: E T A O I N S H R D L C U M W F G Y P B V K J X Q Z

The Vigenère cipher

Vigenère cipher

ci ≡ pi + ki mod ℓ      pi ≡ ci − ki mod ℓ   (mod 26)

Plaintext   keyword

→

The Vigenère square

Row = key letter, column = plaintext letter. Each row is a Caesar shift.

Breaking the Vigenère cipher

  1. 1
    Find the key length ℓ
  2. 2
    Every ℓ-th letter has the same shift: do frequency analysis on each of those groups
  3. 3
    Read off the keyword and decrypt

Step 1: find the key length

LJS appears 6 times. Each time it is “the”, encrypted by the same part of the keyword.

position6580120190260280
distance1540707020

All distances are multiples of 5  ⇒  ℓ = 5

Step 1: count coincidences

Write the ciphertext twice, shift the copy by d, and count the positions where the letters match.

shift d =

Step 2: split into columns

Write the ciphertext in rows of 5.

Every letter in a column was shifted by the same key letter.

So each column is a Caesar cipher.

Step 2: frequency analysis on each column

Column

Choose the shift that makes the English frequencies (outline) closest to the column’s letter distribution.

keyword

Step 3: decrypt

Key CODES  =  2, 14, 3, 4, 18

The Enigma machine

How Enigma works

BLQ rotors lamps keys plugboard
  1. You press a key
  2. The plugboard swaps some pairs of letters
  3. Three rotors each substitute the letter
  4. A reflector sends the signal back
  5. Through the rotors again, then the plugboard
  6. A lamp lights up: the ciphertext letter

After every key press the rotors turn, so the next letter is encrypted with a different substitution.

Enigma simulator

Breaking Enigma

1932

Polish mathematicians
Rejewski, Różycki and Zygalski
first break Enigma

1939

Poland shares its methods
with Britain and France

1940

At Bletchley Park, Turing’s
Bombe machine starts work

  1. No letter encrypts to itself. This rules out many possibilities.
  2. Messages contained predictable words, like “weather report”. These guesses are called cribs.
  3. The Bombe tested rotor settings against a crib automatically.
  4. Operators made mistakes: reused settings, routine phrases.

Placing a crib

The message probably contains WETTERBERICHT (“weather report”). A letter never encrypts to itself, so the crib cannot sit where any of its letters matches the ciphertext.

The one-time pad

One-time pad

The key is truly random, as long as the message, and used only once.

Plaintext   Key

Frank Miller, 1882 · Vernam & Mauborgne, c. 1918 · Washington–Moscow hotline, 1963

Every plaintext is possible

Perfect secrecy

Theorem (Shannon, 1949). If the key K is chosen uniformly at random from all n-letter keys, independently of the plaintext P, and is used for only one message, then for all plaintexts p and ciphertexts c

Pr[P = p | C = c] = Pr[P = p].

Seeing the ciphertext leaves every plaintext exactly as likely as it was before.

Proof (one bit)

Pr(P = 0) = p0,   Pr(P = 1) = p1 = 1 − p0

Key K ∈ {0, 1}, each with probability ½, independent of P

Ciphertext C = P + K (mod 2)

Pr(C = 0 | P = 0) = Pr(K = 0) = ½
Pr(C = 0 | P = 1) = Pr(K = 1) = ½
Pr(C = 0) = ½p0 + ½p1 = ½

Proof (continued)

Pr(P = 0 | C = 0) = Pr(C = 0 | P = 0) Pr(P = 0)Pr(C = 0) = ½ p0½ = p0

Similarly:

Pr(P = 1 | C = 0) = p1
Pr(P = 0 | C = 1) = p0
Pr(P = 1 | C = 1) = p1

So Pr(P = p | C = c) = Pr(P = p) for all p, c.  ∎

Why the key must be uniform

Why the key must never be reused

C1 − C2 = P1 − P2

The key cancels out. Guess a word in one message and you can read the other.

Soviet intelligence reused one-time pad pages printed in 1942. The U.S. Venona project decrypted about 3,000 messages.

Summary