Frequency Analysis Tool

Frequency analysis breaks simple ciphers by counting letters: a cipher that only swaps letters keeps English's uneven shape, so the most common ciphertext letter usually stands for E. Paste ciphertext below to see letter counts, bigrams, trigrams, and the index of coincidence, then test substitutions live.

How to use the frequency analysis tool

  1. Paste ciphertext, or pick a sample. Only the letters A–Z are counted; spaces, digits, and punctuation are ignored.
  2. In the Analysis tab, read the letter distribution, the top bigrams and trigrams, and the IoC badge.
  3. Use the IoC and the letter shape to decide what kind of cipher you have (see the table below).
  4. For a substitution, click Guess Mapping for a first guess by frequency rank, then open the Decoder tab and overwrite letters until words appear.
  5. Copy the report to keep the counts and your current decoded preview.

Every example below is an assumed example: one 326-letter English paragraph written for this page, enciphered five ways. All numbers are calculated from it with the same code the tool runs.

Every letter in a message leaves a fingerprint. When a cipher only swaps one letter for another, the fingerprint survives: the most common symbol in the ciphertext usually stands for E, and the next few stand for T, A, O, and N. That is why a simple substitution can be broken with nothing more than careful counting, while a cipher that changes alphabets from letter to letter hides the pattern far better.

English letter frequencies (reference table)

Ranked from most to least common, the order is ETAOINSHRDLCUMWFGYPBVKJXQZ. E alone is about one letter in eight. The figures below are Robert Lewand's, from Cryptological Mathematics (2000), as reproduced in Wikipedia's letter frequency article. They are rounded and add up to 100.15%; any real text varies around them.

Relative frequency of letters in English text, after Lewand
Letter%Letter%
E12.7M2.4
T9.1W2.4
A8.2F2.2
O7.5G2
I7Y2
N6.7P1.9
S6.3B1.5
H6.1V0.98
R6K0.77
D4.3J0.16
L4X0.15
C2.8Q0.12
U2.8Z0.074

The tool's Guess Mapping uses this order. The table also gives the IoC you should expect from English: about 0.0654, against 0.0385 (1/26) for evenly random letters.

Identify the cipher from its statistics

The same paragraph, enciphered five ways. Compare the index of coincidence and the five most common letters with the plaintext row.

Assumed example: statistics of one plaintext under five ciphers
CipherSettingIoCTop 5 lettersFirst 30 letters
Plaintext (no cipher)none0.0690E T N A REVERYLETTERINAMESSAGELEAVESAFI
Caesarshift 30.0690H W Q D UHYHUBOHWWHULQDPHVVDJHOHDYHVDIL
AtbashA↔Z mirror0.0690V G M Z IVEVIBOVGGVIRMZNVHHZTVOVZEVHZUR
Keyword substitutionkeyword FREQUENCY0.0690U P I F MUTUMXGUPPUMAIFHUOOFCUGUFTUOFNA
Columnar transpositionkey CIPHER0.0690E T N A REENAVNINESNENTGNIEOYNPXLNEEEDO
Vigenèrekey LEMON0.0437Z E F S PPZQFLWIFHRCMZOZPWEOTPPQOIPWMTV
  • IoC close to English, same letters on top as English (E T N A R): a transposition. It only reorders letters, so the counts match the plaintext exactly. Try the columnar transposition or rail fence tools.
  • IoC close to English, different letters on top: a single-alphabet substitution. Caesar (H W Q D U) and Atbash (V G M Z I) are fixed rearrangements, so test those first; otherwise treat it as a general substitution (U P I F M).
  • IoC well below English (0.0437 here): several alphabets are in use, as in Vigenère. Frequency analysis still works, but only after you find the key length.

Note that substitution and transposition give the plaintext's exact IoC of 0.0690: both keep the number of times each symbol appears. IoC alone cannot separate them; the letter shape can.

Find a Caesar shift with a chi-squared score

A Caesar cipher has only 26 possible shifts, so you can score all of them. For each shift, decode the text, count the letters, and compute the chi-squared distance from the reference table: the sum of (observed − expected)² ÷ expected over the 26 letters. The lowest score is the most English-looking.

Assumed example: the Caesar row above (shift 3). The three lowest scores out of 26:

Assumed example: best three Caesar shifts by chi-squared
Decrypt shiftChi-squaredDecoded start
324.7EVERYLETTERINAMESSAGELEA
16827.5RIRELYRGGREVANZRFFNTRYRN
91076.7YPYLSFYNNYLCHUGYMMUAYFYU

The correct shift wins by a wide margin. On short texts the gap narrows, so read the decoded start rather than trusting the score alone. The Caesar cipher tool lists all 25 shifts if you want to check by eye.

Vigenère: find the key length first

For repeat-distance and factor evidence to compare with column IoC, follow the worked Kasiski examination in our Vigenère decoding guide.

A Vigenère key of length n shifts every n-th letter by the same amount. Split the ciphertext into n columns (letters 1, n+1, 2n+1…, then 2, n+2…). At the right length, each column is a plain Caesar cipher and its IoC rises back toward English.

Assumed example: the Vigenère row above (key LEMON). Average column IoC for guessed lengths 1–7:

Assumed example: average column index of coincidence by guessed key length
Guessed key lengthAverage column IoC
10.0437
20.0435
30.0440
40.0429
50.0713 ← highest
60.0477
70.0411

Length 5 stands out, and it is the length of LEMON. With the length known, run each column through the Caesar chi-squared test above to recover one key letter per column. You can then decrypt in the Vigenère cipher tool. This tool shows the whole-text IoC only; the column split is done by hand or in a spreadsheet.

How much text you need

Assumed example: the first n letters of the sample plaintext, before any cipher is applied.

Assumed example: statistics by sample length
LettersIoCTop 3Top letter shareDistinct letters
200.0737E A R25%12 of 26
500.0800E A R22%17 of 26
1000.0754E R N18%19 of 26
2000.0653E T N13.5%22 of 26
3260.0690E T N13.5%23 of 26

Short samples swing: the IoC ran above English at 20–100 letters, and second and third place changed until about 200 letters. E stayed on top throughout in this sample, but that is not guaranteed in other texts. Treat counts from under about 100 letters as hints, and lean on word patterns such as THE and one-letter words.

What Guess Mapping gets right, and what it doesn't

Guess Mapping maps the most frequent ciphertext letter to E, the second to T, and so on down the reference order. Assumed example: the keyword substitution row above (keyword FREQUENCY, cipher alphabet FREQUNCYABDGHIJKLMOPSTVWXZ).

  • Letters present in the ciphertext: 23.
  • Mapped correctly: 4 (E M T V), covering 29.4% of the letters in the text.

Guessed: EVEIBDETTEIHAOMENNOFEDEOVENOCHAFEILIHATY

Actual: EVERYLETTERINAMESSAGELEAVESAFINGERPRINTW

That is normal: only the very top of the ranking is stable in a few hundred letters. Keep the letters that produce real words, then fix the rest with word patterns. The step-by-step substitution solving guide works a full example from counts to plaintext, and the substitution cipher tool checks a recovered key.

When frequency analysis won't help

  • Very short messages: the counts are noise (see the table above).
  • Non-English or unusual text: other languages have different frequency tables, and lists of names or codes skew the counts.
  • Encodings that are not letter ciphers, such as Base64 or hex: the tool counts only A–Z, so these give misleading numbers. Try the cipher identifier first.
  • Modern encryption such as AES: its output does not keep letter statistics.

History

The earliest known description of frequency analysis is attributed to the ninth-century Arab scholar Al-Kindi, in a manuscript on deciphering cryptographic messages, as summarized in Wikipedia's frequency analysis article.

The method is why simple substitution stopped being trusted for serious secrecy. Polyalphabetic ciphers such as Vigenère were designed to flatten the letter counts, and the key-length test shown above is part of how they were broken in turn.

Frequently asked questions

What is frequency analysis in cryptography?

Frequency analysis counts how often each letter, or group of letters, appears in a ciphertext and compares the counts with the known letter frequencies of a language. A cipher that only relabels letters keeps the shape of those counts, so the shape points to the likely plaintext letters.

Is there a frequency analysis decoder that solves the cipher automatically?

The Guess Mapping button in this tool maps the most frequent ciphertext letter to E, the next to T, and so on down ETAOIN. That is only a first guess. On this page's 326-letter keyword-substitution example it placed 4 of 23 letters correctly (covering 29.4% of the letters in the text). You finish the solve by correcting the mapping in the Decoder tab until words appear.

What is a frequency attack?

A frequency attack is the same idea used against a cipher: the attacker relies on the uneven use of letters or symbols to guess the key without trying every possible key. It defeats Caesar, Atbash, and simple substitution ciphers given enough text, and it is the first step against Vigenère once the key length is known.

What does the index of coincidence tell me?

It is the chance that two letters picked at random from the text are the same. Text following the English reference table scores about 0.0654; evenly random letters score about 0.0385. In the examples on this page, Caesar, Atbash, substitution, and transposition all kept the plaintext's 0.069, while Vigenère with key LEMON dropped to 0.0437.

How much ciphertext do I need for frequency analysis?

More text gives steadier counts. In this page's sample, the first 100 letters ranked E R N as the top three, and it took 200 letters before the ranking settled on E T N. Under about 100 letters, lean on word patterns such as THE and single-letter words rather than raw counts.

Does frequency analysis work on the Vigenère cipher?

Not on the whole ciphertext, because each position uses a different shift and the counts flatten. Split the text into columns by a guessed key length and check each column. In this page's example the average column index of coincidence jumped to 0.0713 at length 5, the real key length, and each column can then be solved like a Caesar cipher.

Can frequency analysis tell a transposition cipher from a substitution cipher?

Yes, often. A transposition only reorders letters, so its counts match ordinary English letter for letter: E, T, and A stay on top. A substitution keeps the same uneven shape but under different letters. If the top ciphertext letters already look like E, T, A, O, N, suspect transposition.

Is the text uploaded anywhere?

No. The tool runs in your browser, so your ciphertext and substitution mapping stay on your device.