Virtual laboratory/Mathematics/Cryptography/Letter frequency analysis

Letter frequency analysis

In every language letters have a characteristic frequency. A substitution cipher changes the symbols but not their distribution — compare the histograms and break the cipher.

Letter frequency analysis
Mathematics · Cryptography · Letter frequency analysis
Plaintext language
Cipher shift ss3
A substitution cipher can be broken by analysing:
language
PL
most frequent letter
A
shift s
+3
most frequent symbol
D
🎯 Challenge: the most frequent letter
streak: 0

I’ll give you a language — point out its most frequent letter. It is the one that gives the substitution away in cryptanalysis.

What is going on here?

In every language, letters appear with a fixed, characteristic frequency. In Polish the most frequent are A, I, O, E, in English E, T, A. This “signature” of a language is very robust — a few hundred characters are enough for it to show.

Relative letter frequency:

fi=niNf_i = \dfrac{n_i}{N}

where nin_i is the number of occurrences of the letter and NN — the total number of letters in the text. The set of values {fi}\{f_i\} is exactly the frequency distribution that we draw as a histogram.

Why does this break a substitution cipher?

A substitution cipher replaces each letter with another fixed symbol (here: a shift of ss positions). This is only a relabelling — the letter assigned to a symbol still occurs just as often:

cipher[j]=plain[(j−s) mod 26]\text{cipher}[j] = \text{plain}\big[(j - s)\bmod 26\big]

That is why the ciphertext histogram has exactly the same shape as the plaintext histogram — only shifted and relabelled. The most frequent ciphertext symbol almost certainly corresponds to the most frequent letter of the language. Matching the tallest bars reveals the substitution.

The invariant:

Substitution preserves the frequency distribution — it only changes the names of the symbols. The shape of the histogram is invariant under substitution, and it is the shape, not the text length, that gives the cipher away.

A bit of history:

Frequency analysis was described as early as the 9th century by the Arab scholar al-Kindi in a treatise on reading encrypted messages — the first known account of cryptanalysis. The same idea later broke the famous Vigenère cipher and still forms the foundation of classical cryptanalysis.

Why you need this for the exam:

Frequency analysis is a flagship example that information can “leak” even through a seemingly secure cipher. The trick: look for what a transformation leaves unchanged — the invariant. Here it is the frequency distribution.

Remember: substitution shuffles labels but not frequencies — the most frequent cipher symbol is the most frequent letter of the language.

Illustrative model · NexTutor Virtual Laboratory

Enjoyed the experiment? Share it.

It's free — send it to friends from school.

Theory & formulas

The principle

A substitution cipher replaces each letter with another according to a fixed mapping, but does not change how often it occurs. The frequency histogram stays the same — only the symbol labels change.

Breaking the cipher

The most frequent symbol in the ciphertext corresponds to the most frequent letter of the language (in English, usually the letter E). By matching the distributions, we recover the letter mapping.

Conclusion

Even a huge key space (for 2626 letters as many as 26!26!) offers no protection if the statistics of the text "shine through" the cipher.

Notation: 26!26! the number of possible alphabet substitutions.

Frequently asked questions

›

How is a substitution cipher broken?

By analyzing symbol frequencies — the most frequent one in the ciphertext corresponds to the most frequent letter of the language.

›

Why does this work?

Because substitution changes only the symbol labels, not the shape of the frequency distribution.

Teaching? Embed this experiment on your site.

Free widget — paste it on your school site, blog or notes. It links to the full version.

Teaching a class or tutoring? Guide students in NexTutor →