Homophonic Substitution Cipher

Type a message to encode it with a simplified homophonic substitution cipher.

How it is calculated

The text is converted to upper case and only the letters A to Z are encoded; spaces, digits, punctuation and accented letters are skipped and not counted. The hundred codes 00 to 99 are divided among the 26 letters roughly in proportion to English letter frequency (Cornell's count from 40,000 words, rounded to whole codes so that they add up to 100): E 12, T 9, A 8, O, I and N 7, S, R and H 6, D and L 4, U 3, C, M, F, Y, W, G and P 2, and B, V, K, X, Q, J and Z 1 each. The sets do not overlap and are scattered over 00 to 99 by a fixed permutation, so every code stands for exactly one letter: that is what the Handbook of Applied Cryptography (§ 7.3.2) requires for the cipher to be decodable.

The Handbook picks a code from the letter's set at random; this tool takes them in turn (a letter's first occurrence gets the first code of its set, the next occurrence the second, and so on, starting again after the last), so the same message always gives the same output. Decode reverses it: each two-digit code is looked up and replaced by its letter. With a fixed, published table this is a teaching demo only and must not be used to protect anything.

Worked example

Encode HELLO. H has the codes 58, 95, 32, 69, 06, 43; E has twelve, starting 66, 03, 40; L has 13, 50, 87, 24; O has 94, 31, 68 and four more. Each letter takes the next unused code of its own set, so H → 58, E → 66, the first L → 13, the second L → 50 and O → 94. The tool outputs 58 66 13 50 94 and reports 5 letters. The two Ls got different codes, yet both decode to L, because 13 and 50 belong to L alone: choose Decode and enter 58 66 13 50 94 to get HELLO back.

Try this example →

Common mistakes

  • Expecting secrecy. The code table is fixed and printed in the method, so anyone can decode the output.
  • Counting spaces and punctuation as letters. Only A to Z are encoded, so 'Hello, World' gives 10 codes, not 12.
  • Typing accented or non-Latin letters such as ş, ğ or ü. They are ignored; a text with no A to Z letters gives no result.
  • Assuming the same letter always gets the same code, as in a plain substitution cipher. A repeated letter moves on through its own set of codes.
  • Decoding with anything but two-digit codes separated by spaces or commas. A three-digit number or a letter in the input gives no result.

Sources

About this calculator

A homophonic substitution cipher improves on a plain substitution cipher (where each letter always maps to the same symbol) by giving common letters several interchangeable codes instead of just one. Because a letter like “e” might be replaced by any of several different 2-digit numbers depending on where it appears, the resulting ciphertext has a flatter, more uniform distribution of symbols, which defeats simple frequency analysis — the classic technique of counting symbol frequency to guess which cipher-symbol represents “e”, “t”, and so on.

Historical nomenclators and “great ciphers” used by diplomats and spies from the Renaissance through the 19th century (and famously the Zodiac Killer's 340-character cipher, solved only in December 2020 by David Oranchak, Sam Blake and Jarl Van Eycke) relied on this same many-to-one idea. This tool is an educational demonstration of the cipher as the Handbook of Applied Cryptography defines it: the hundred codes 00 to 99 are shared out among the letters roughly in proportion to how often each occurs in English (E has 12, T 9, A 8, and the rarest letters one each), no code belongs to two letters, and a repeated letter takes the next code in its set. So the ciphertext can always be decoded, which the tool also does, and the codes come out far more evenly than the letters.

Was this helpful?

You can pick up to 3 reactions.

Note from the editors

Use this for puzzles and classroom demos, not secrecy. You can check an output by hand: HELLO gives 58 66 13 50 94, and the two L's become 13 and 50 because L owns four codes and takes them in turn. Since no code belongs to two letters, Decode turns 58 66 13 50 94 straight back into HELLO. What are you using the codes for: a puzzle, a lesson, or a game?

Comments

  • Be the first to comment.

Popular calculators

All Calculators