Skip to content
Infinitesimal Dynamics home
Notebook: 0 XP

Cryptography / Classical ciphers

Substitution and Shift Ciphers

Caesar, affine and Vigenère ciphers, written as modular arithmetic.

3 min read · 2 sections · 2 checks

Contents 3 sections
  1. §1Shifting the alphabet
  2. §2Vigenère
  3. ?Check yourself

By the end you can

  • Encrypt and decrypt with shift and affine ciphers
  • Describe a cipher by its key space
  • Explain how Vigenère hides letter frequencies

§1Shifting the alphabet

Number the letters A=0A = 0 to Z=25Z = 25. A shift cipher with key kk encrypts x↦x+k(mod26)x \mapsto x + k \pmod{26} and decrypts by subtracting. Julius Caesar reportedly used k=3k = 3.

There are only 26 keys, so an attacker can try them all: a brute-force attack. A secure cipher needs a key space far too large to search.

§2Vigenère

The Vigenère cipher uses a keyword and shifts each letter by the corresponding keyword letter, cycling through it. The same plaintext letter encrypts differently in different positions, which flattens the letter frequencies that betray a simple substitution.

Preparing the instrument…
Fig. 1 Encrypt your own message, then switch to the analysis view and watch the frequencies give the key away.

Check yourself

  1. Q1
    With a Caesar shift of 3, the plaintext CAB encrypts to…
  2. Q2
    Which value of aa is allowed in an affine cipher mod 26?