Chris Spackman's NeoCities Page

Substitution Cipher

A substitution cipher replaces each letter in the message with a different letter. Instead of shifting the whole alphabet by a fixed amount (like the Caesar cipher), each letter maps to its own unique replacement. Think of it as scrambling the entire alphabet — A might become Q, B might become M, C might become Z, and so on.

The Scrambled Alphabet Analogy

Imagine writing the normal alphabet on one strip of paper and a completely shuffled alphabet on another. Line them up, and you have your key. To encrypt, find each letter on the top strip and replace it with the letter below it. To decrypt, do the reverse — find the letter on the bottom strip and read the one above it.

A Huge Key Space

Because any of the 26 letters can map to any unused letter, the total number of possible keys is 26! (26 factorial) = 403,291,461,126,605,635,584,000,000. That is roughly 4 × 1026. Unlike the Caesar cipher's 26 keys, this key space is far too large for a brute-force attack. So why can it still be broken? Read on.

Try It

Result

Letter-by-Letter

Frequency Analysis

The chart below compares how often each letter appears in the ciphertext (red bars) with how often letters normally appear in English (green bars). With longer messages, the pattern of the ciphertext bars starts to match the English bars — just shifted to different letters.

How It Works

The key is a permutation of the alphabet — a rearrangement where each letter appears exactly once. For example:

To encrypt the word "HELLO":

So "HELLO" becomes "ITSSG". To decrypt, reverse the lookup: find each ciphertext letter in the cipher row and read the plaintext letter above it.

Why It Can Be Broken

Even though brute force is impossible, the substitution cipher has a fatal weakness: frequency analysis. In English, certain letters appear far more often than others — E is the most common (about 12.7%), followed by T (9.1%), A (8.2%), and so on. Because a substitution cipher is monoalphabetic — each plaintext letter always maps to the same ciphertext letter — these frequency patterns survive the encryption.

An attacker can count how often each letter appears in the ciphertext, then match the most frequent ciphertext letters to the most frequent English letters. Common two-letter and three-letter combinations (like "TH", "THE", "AND") provide additional clues. With a reasonably long message, the cipher can be broken without ever trying a single key.

Things to Try

Disclaimer: these pages are educational demos provided as-is, with no warranty of any kind. The author is not responsible for any consequences arising from their use.

Send comments and bug reports to chris@chrisspackman.com.

Version 0.1 — Last updated: 2026-02-21

This page is Copyright © 2025 – 2026 Chris Spackman <chris@chrisspackman.com>.
This web site developed entirely on GNU/Linux with Free / Open Source Software.

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Creative Commons License