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. For each letter, take its index i (A = 0 … Z = 25) and its position p among the letters (first letter = 0). The code is (3 × i + p) mod 99, written with two digits and separated by spaces.

Because the position is part of the formula, the same letter gets a different code each time it appears, which is the many-to-one idea behind homophonic ciphers. Unlike a real homophonic cipher with a fixed table of alternatives, the code here is a simple rule, and it is reproducible: the same message always gives the same output. Codes wrap around after 98 (the next one is 00). This is a teaching demo only, with no key and no decoder, and it must not be used to protect anything.

Worked example

Encode HELLO. The letters have indexes H = 7, E = 4, L = 11, L = 11, O = 14, at positions 0 to 4. H: 3 × 7 + 0 = 21. E: 3 × 4 + 1 = 13. First L: 3 × 11 + 2 = 35. Second L: 3 × 11 + 3 = 36. O: 3 × 14 + 4 = 46. The tool outputs 21 13 35 36 46 and reports 5 letters. Note that the two Ls became different codes, 35 and 36, even though they are the same letter.

Try this example →

Common mistakes

  • Expecting a decoder or a secret key. The tool only encodes with a fixed rule; anyone who knows the rule can reverse it, so it offers no security.
  • 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. Here it depends on the letter's position in the message.
  • Thinking this is how historical homophonic ciphers worked. Real ones used a table with several symbols per common letter; this is a simplified position-based demo.

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 unsolved Zodiac Killer’s 340-character cipher) relied on this same many-to-one idea. This tool is an educational demonstration: type a message and it encodes each letter into a 2-digit code that shifts with position, letting you see how homophonic substitution scrambles letter frequency compared to a simple one-to-one cipher.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Use this for puzzles and classroom demos, not secrecy. You can check an output by hand: HELLO gives 21 13 35 36 46, and the two L's become 35 and 36 because each code is three times the letter index plus its position, wrapped at 99. The second L being one higher than the first shows that position is built in. What are you using the codes for: a puzzle, a lesson, or a game?

Popular calculators

All Calculators