Classic Ciphers

Journey through history's most influential ciphers — each with background, principles, and interactive demos

Caesar Cipher

Classical Beginner Substitution

The Caesar cipher is one of the oldest and simplest encryption techniques. Named after Julius Caesar, who used it for military correspondence around 58 BC, it shifts each letter in the plaintext by a fixed number of positions down the alphabet.

Background

Julius Caesar used a shift of 3 to communicate with his generals. While trivial to break by modern standards, it was effective in an era when few people could read at all, let alone analyze encrypted text. Suetonius documented Caesar's use of this cipher in his work "Life of Julius Caesar."

Encryption Principle

Each letter in the message is replaced by a letter a fixed number of positions down the alphabet. With a shift of 3:

  • A → D, B → E, C → F, ... X → A, Y → B, Z → C
  • Non-alphabetic characters (spaces, numbers, punctuation) are typically left unchanged.

Decryption Method

Shift each letter back by the same number of positions. With shift 3, D → A, E → B, etc. Alternatively, shift forward by (26 - shift) positions.

Security

The Caesar cipher has only 25 possible keys (shifts 1-25), making it vulnerable to brute force attack — simply try all shifts. It is also vulnerable to frequency analysis, as each letter always maps to the same ciphertext letter.

Interactive Demo

Try It Yourself

Result appears here

Real-World Applications

While the Caesar cipher is never used for serious security today, it appears in:

  • ROT13: A special case (shift 13) used in online forums to hide spoilers.
  • Children's codes: Secret decoder rings and puzzle games.
  • Education: The classic first lesson in any cryptography course.

Vigenere Cipher

Classical Intermediate Polyalphabetic

The Vigenere cipher is a polyalphabetic substitution cipher that uses a keyword to determine different Caesar shifts for each letter. For nearly 300 years it was known as "le chiffre indechiffrable" — the indecipherable cipher.

Background

Originally described by Giovan Battista Bellaso in 1553, the cipher was later misattributed to Blaise de Vigenere. It resisted all attempts at cryptanalysis until Charles Babbage and Friedrich Kasiski independently broke it in the 1860s using what is now called the Kasiski examination.

Encryption Principle

Each letter of the plaintext is shifted by an amount determined by the corresponding letter of the keyword. If the keyword is shorter than the message, it repeats.

  • Plaintext: H E L L O W O R L D
  • Keyword: K E Y K E Y K E Y K
  • Shift: 10 4 24 10 4 24 10 4 24 10
  • Result: R I J V S Q Y V J N

Decryption Method

Reverse the process: subtract the keyword's shift value from each ciphertext letter.

Security

The Vigenere cipher is stronger than Caesar because frequency analysis alone cannot break it — the same plaintext letter can encrypt to different ciphertext letters. However, if the keyword length can be determined (via Kasiski examination or Friedman test), the cipher reduces to multiple Caesar ciphers that can be broken individually.

Interactive Demo

Try It Yourself

Result appears here

Real-World Applications

  • Historically used for diplomatic and military communications in the 16th-19th centuries.
  • The Confederate States used a Vigenere variant during the American Civil War, which was routinely broken by Union cryptanalysts.

Rail Fence Cipher

Classical Beginner Transposition

The Rail Fence cipher is a transposition cipher that writes the message in a zigzag pattern across multiple "rails" (rows), then reads off each row sequentially to create the ciphertext.

Background

The Rail Fence cipher is one of the simplest transposition ciphers. Unlike substitution ciphers that replace letters, transposition ciphers rearrange the positions of letters without changing them.

Encryption Principle

With 3 rails, "HELLO WORLD" is written as:

H . . . O . . . R . .
. E . L . W . O . L .
. . L . . . . . D . .

Reading off each row: HOR ELWOL LDHORELWOLLDD

Interactive Demo

Try It Yourself

Result appears here

Atbash Cipher

Classical Beginner Substitution

The Atbash cipher is a simple substitution cipher that reverses the alphabet: A maps to Z, B to Y, C to X, and so on. Originally used with the Hebrew alphabet, it dates back to Biblical times.

Key Property

The Atbash cipher is its own inverse — applying it twice returns the original text. Encryption and decryption are the same operation.

Interactive Demo

Try It Yourself

Result appears here

ROT13

Classical Beginner Substitution

ROT13 ("rotate by 13 places") is a special case of the Caesar cipher with a fixed shift of 13. Since the English alphabet has 26 letters, applying ROT13 twice returns the original text.

Background

ROT13 became popular in the early days of the internet (1980s) on Usenet newsgroups. It was used to hide spoilers, punchlines to jokes, or potentially offensive content — not for security, but as a courtesy to readers who could choose whether to decode it.

Interactive Demo

Try It Yourself

Result appears here

Affine Cipher

Classical Intermediate Substitution

The Affine cipher is a monoalphabetic substitution cipher that uses a mathematical function to map each letter: E(x) = (ax + b) mod 26, where a must be coprime with 26 (i.e., a ∈ {1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25}).

Encryption Principle

Each letter (converted to a number 0-25) is multiplied by a, added to b, and taken modulo 26. The result is converted back to a letter.

Interactive Demo

Try It Yourself

Result appears here

Keyword Substitution Cipher

Classical Beginner Substitution

The keyword substitution cipher creates a custom alphabet by placing a keyword at the beginning, followed by the remaining letters in order (skipping any already used). This creates a simple but effective monoalphabetic substitution.

How It Works

With keyword "CIPHER":

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

Interactive Demo

Try It Yourself

Result appears here

Playfair Cipher

Classical Intermediate Digraph

The Playfair cipher encrypts pairs of letters (digraphs) instead of single letters, making it significantly harder to break than simple substitution ciphers. It was invented by Charles Wheatstone in 1854 but named after Lord Playfair, who promoted its use.

How It Works

A 5x5 grid is filled using a keyword (I and J share a cell). Letters are paired, and three rules determine how each pair is encrypted based on their positions in the grid:

  • Same row: Replace each with the letter to its right (wrapping around).
  • Same column: Replace each with the letter below it (wrapping around).
  • Rectangle: Replace each with the letter in the same row but in the column of the other letter.

Interactive Demo

Try It Yourself

Result appears here

Historical Significance

The Playfair cipher was used by British forces during the Second Boer War and World War I, and by the Australians during World War II. It was the first cipher to encrypt digraphs, making frequency analysis much more difficult.

Morse Code

Classical Beginner Encoding

Morse code is a method of encoding text as sequences of short signals (dots, .) and long signals (dashes, -). Developed by Samuel Morse and Alfred Vail in 1838, it revolutionized long-distance communication via telegraph.

The Code

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

0 -----  1 .----  2 ..---  3 ...--  4 ....-
5 .....  6 -....  7 --...  8 ---..  9 ----.

Interactive Demo

Try It Yourself

Result appears here

Real-World Applications

  • The international distress signal SOS (... --- ...) is recognized worldwide.
  • Still used by amateur radio operators and in aviation/maritime navigation.
  • Accessibility tool for people with disabilities to communicate via simple switches.

Enigma Machine

Classical Advanced Electro-mechanical

The Enigma machine was an electro-mechanical rotor cipher machine used by Nazi Germany during World War II. Its complexity — with rotors, plugboards, and reflectors creating approximately 158 trillion possible settings — made it one of the most sophisticated encryption devices of its time.

How It Worked

The Enigma machine consisted of several key components:

  • Keyboard: For inputting letters (no numbers or punctuation).
  • Rotors (3-4): Each rotor performed a substitution cipher. After each key press, the rightmost rotor advanced by one position, changing the substitution path. After 26 presses, the middle rotor advanced, and so on — like an odometer.
  • Reflector: After passing through the rotors, the signal hit a reflector that sent it back through the rotors via a different path, ensuring encryption and decryption used the same process.
  • Plugboard (Steckerbrett): Swapped pairs of letters before and after the rotor path, adding another layer of complexity.

Breaking Enigma

The Polish Cipher Bureau made the first significant breakthroughs in the 1930s, passing their work to British and French intelligence in 1939. At Bletchley Park, Alan Turing and his team developed the Bombe — an electro-mechanical device that could rapidly eliminate impossible rotor configurations, dramatically reducing the search space.

Impact

Historians estimate that breaking Enigma shortened World War II by at least two years and saved millions of lives. The work at Bletchley Park also laid the foundations for modern computer science and artificial intelligence.

Simplified Interactive Demo

Simplified Enigma Simulation (3 rotors, no plugboard)

This is a simplified simulation. The real Enigma had plugboards and more complex rotor wiring.

Result appears here
Note: Enter the same rotor positions and paste the output back to decrypt (Enigma is reciprocal — same operation encrypts and decrypts).

Columnar Transposition Cipher

Classical Intermediate Transposition

The Columnar Transposition cipher writes the plaintext into a grid of columns defined by a keyword, then reads the columns off in alphabetical order of the keyword letters. Unlike substitution ciphers, it rearranges letter positions rather than replacing them.

Background

Columnar transposition was used extensively by military forces during the 19th and 20th centuries. The Union Army used it during the American Civil War, and it formed part of German Abwehr cipher systems during World War II. When combined with substitution ciphers, it becomes significantly harder to break.

Encryption Principle

  1. Write the keyword above the message grid.
  2. Fill the grid row by row with the plaintext.
  3. Number the keyword letters alphabetically (A=1, B=2, etc.).
  4. Read off columns in the order determined by the numbered keyword.

Example with keyword "ZEBRA" and message "WE ARE DISCOVERED":

Z E B R A
5 2 1 4 3
W E A R E
D I S C O
V E R E D

Read in alphabetical column order (B, E, A, R, Z): ASR EIIEV EOED WCDV

Security

Alone, columnar transposition is vulnerable to anagramming attacks. However, when combined with substitution (as in a product cipher), it becomes much stronger. The combination of transposition and substitution is the basis for many modern encryption principles.

Interactive Demo

Try It Yourself

Result appears here

Autokey Cipher

Classical Intermediate Polyalphabetic

The Autokey cipher (also known as the autoclave cipher) is a polyalphabetic substitution cipher that uses the plaintext itself as part of the key after the initial keyword is exhausted. This eliminates the repetitive pattern that makes the Vigenere cipher vulnerable to Kasiski analysis.

Background

The Autokey cipher was proposed by Blaise de Vigenere in 1586 as an improvement to the cipher that bears his name. By using the plaintext as part of the key, it avoids the critical weakness of the Vigenere cipher: the repetition of the keyword.

Encryption Principle

Given a keyword "KEY" and plaintext "HELLO":

  • The full key becomes: KEYHE (keyword + plaintext)
  • Each plaintext letter is shifted by the corresponding key letter:
  • H+K=R, E+E=I, L+Y=J, L+H=S, O+E=S
  • Result: RIJSS

Security Advantage Over Vigenere

Because the key does not repeat, the Kasiski examination — the primary method for breaking Vigenere — is ineffective against Autokey. However, if a portion of the plaintext can be guessed (a "crib"), the rest can be recovered progressively.

Interactive Demo

Try It Yourself

Result appears here