Introduction
The Vigenere cipher resisted cryptanalysis for 300 years until Kasiski and Friedman independently discovered how to exploit its repeating key. This tool automates the full attack: it tests key lengths 1 through N using the Index of Coincidence, selects the length whose columns most closely match English, then recovers each key letter by trying all 26 shifts and picking the one with the lowest chi-squared value. Paste your ciphertext, click Solve, and the tool outputs the recovered key and decrypted text with a full step-by-step trace.
What this tool does
- Determine the Vigenere key length by computing the average Index of Coincidence for each candidate length from 1 to a configurable maximum (default 20)
- Recover each key letter by splitting the ciphertext into columns, trying all 26 Caesar shifts per column, and selecting the shift with the lowest chi-squared statistic against English letter frequencies
- Decrypt the full ciphertext with the recovered key, preserving the original case and non-letter characters in the output
- Display a step-by-step trace showing the IoC for each key length, the chi-squared values for each shift at each key position, and the final recovered key
- Render an IoC bar chart comparing all tested key lengths, with the selected length highlighted, alongside reference lines for English IoC (0.0667) and random IoC (0.0385)
- Show a per-position chi-squared table with the best shift, corresponding letter, and chi-squared value for each key position
How this tool works
The solver operates in three phases. Phase 1 determines the key length. For each candidate length L from 1 to the maximum, the ciphertext is split into L columns (character 0 goes to column 0, character 1 to column 1, ..., character L to column 0, etc.). The Index of Coincidence is computed for each column as: sum over all letters of count(letter) * (count(letter) - 1) / (n * (n - 1)), where n is the column length. The average IoC across all columns is recorded. The key length with the highest average IoC (closest to English's 0.0667) is selected.
Phase 2 recovers the key letters. For each of the L columns, the solver tries all 26 shifts. For each shift, it decrypts the column (subtracting the shift value modulo 26 from each letter) and computes the chi-squared statistic against standard English letter frequencies. The shift producing the lowest chi-squared value is selected as the key letter for that position. The letter is determined by `String.fromCharCode(shift + 65)`.
Phase 3 decrypts the full ciphertext. The solver iterates over the original ciphertext (preserving case and non-letter characters), applying the Vigenere decryption formula: `plaintext[i] = (cipher[i] - key[i mod L] + 26) mod 26`. The key index only advances for letter characters, so spaces and punctuation do not consume key positions.
The entire process runs synchronously after a brief yield to the event loop for UI responsiveness. Results are displayed in the step-by-step output, IoC bar chart, and chi-squared table.
How automated Vigenere cracking works (Friedman, Kasiski)
The Vigenere cipher was originally described by Giovan Battista Bellaso in 1553 but was misattributed to Blaise de Vigenere in the 19th century. It was considered unbreakable for nearly 300 years until Friedrich Kasiski published his method in 1863 in 'Die Geheimschriften und die Dechiffrir-Kunst'. Kasiski's key insight was that repeated sequences in the ciphertext, when separated by distances that share a common factor, reveal the key length.
William F. Friedman independently developed a statistical approach in the 1920s, introducing the Index of Coincidence in his 1922 Riverbank Publication No. 22, 'The Index of Coincidence and Its Applications in Cryptanalysis'. Friedman's IoC method does not require finding repeated sequences. Instead, it measures the probability that two randomly selected letters from a text are the same. English text has an IoC of about 0.0667, while random text has an IoC of about 0.0385. When a Vigenere ciphertext is split into columns by the correct key length, each column is a monoalphabetic Caesar cipher, and its IoC approaches 0.0667.
The chi-squared key recovery method works because each column of a Vigenere ciphertext (when split by the correct key length) is a simple Caesar cipher. Trying all 26 shifts and computing chi-squared against English frequencies for each shift identifies the correct one: the shift that makes the column's letter distribution most closely match English.
This tool combines both Friedman's IoC method (for key length) and chi-squared analysis (for key letters) into a single automated attack. For the underlying Vigenere cipher implementation, see the Vigenere Cipher. For manual key length analysis, see the Kasiski Examination and Index of Coincidence tools. For autocorrelation-based key length detection, see the Autocorrelation Cipher Detector.
How to use this tool
- Paste your Vigenere ciphertext into the input field. The tool requires at least 20 letters and works best with 100 or more
- Set the maximum key length to test (default 20). If you know the key is shorter, reduce this to speed up the analysis
- Click 'Solve Vigenere Cipher'. The tool runs the three-phase attack: key length detection, key letter recovery, and decryption
- Review the IoC bar chart to see how the Index of Coincidence varies by key length. The selected length is highlighted
- Check the chi-squared table for each key position to see which shift was selected and how confident the selection is (lower chi-squared = more confident)
- Read the recovered key and decrypted text in the final results section. The decrypted text preserves original case and non-letter characters
Real-world examples
Cracking a 300-character Vigenere with a 6-letter key
Paste a 300-character Vigenere ciphertext encrypted with the key 'CIPHER'. The IoC chart shows a clear peak at key length 6 (IoC 0.065, close to English). The chi-squared table shows shifts 2, 8, 15, 7, 4, 17 for the 6 positions, which correspond to the letters C, I, P, H, E, R. The decrypted text is readable English.
Handling a ciphertext with an unknown key length
Set the maximum key length to 20 and paste a 500-character ciphertext. The IoC chart shows peaks at lengths 4, 8, 12, and 16. The tool selects length 4 (the smallest with the highest IoC) because 8, 12, and 16 are multiples. The recovered 4-letter key decrypts the text correctly.
Solving a CTF Vigenere challenge
A CTF challenge provides a 200-character Vigenere ciphertext. Paste it, set max key length to 15, and click Solve. The tool outputs the recovered key and decrypted text. The flag is visible in the decrypted text. The step-by-step trace shows the IoC and chi-squared values that led to the solution, which is useful for writeups.
Dealing with a short ciphertext (50 characters)
With only 50 characters, the IoC values are noisy and the chi-squared per column may not clearly identify the correct shift. The tool will still produce a best guess, but it may be wrong. Try running it multiple times (the IoC computation is deterministic, so the result will be the same). For short texts, manual analysis using the Vigenere Cracker may be more effective.
Comparison with similar methods
| Method | Complexity | Typical use |
|---|---|---|
| IoC + chi-squared (this tool) | O(maxKeyLen * n + maxKeyLen * 26 * n) | Automated Vigenere cracking |
| Kasiski + chi-squared | O(n^2) for repeated sequence search | Manual analysis, long ciphertexts |
| Autocorrelation + chi-squared | O(maxShift * n) for autocorrelation | Alternative key length detection |
| Friedman test (formula) | O(n) for single IoC, formula-based estimate | Quick key length estimate |
| Dictionary attack | O(dictionary_size * n) | When key is a known word |
Limitations or considerations
The solver requires at least 20 letters of ciphertext and works best with 100 or more. With short texts, the IoC values are noisy and the chi-squared per column may not reliably identify the correct shift. For texts under 50 characters, consider manual analysis with the Vigenere Cracker.
The IoC-based key length detection selects the length with the highest average IoC. If the ciphertext is short, multiple key lengths may have similar IoC values, and the tool may select the wrong one. Cross-check with the Autocorrelation Cipher Detector or Kasiski Examination for confirmation.
The chi-squared key recovery assumes the ciphertext is English. For other languages, the standard English letter frequencies will produce incorrect shifts. The tool does not support custom frequency distributions (unlike the Chi-Squared Calculator).
The solver does not handle autokey ciphers, where the key is extended with the plaintext. Autokey ciphers do not have a repeating key, so IoC-based key length detection does not apply.
If the key contains letters that produce chi-squared values very close to another shift, the tool may select the wrong letter. This is more common with short columns. The chi-squared table shows the values, so you can identify ambiguous positions and try alternatives manually.
Frequently asked questions
How does the tool determine the Vigenere key length?
It computes the average Index of Coincidence for each candidate key length from 1 to the maximum. The IoC measures how likely two random letters from the same column are identical. When the key length is correct, each column is a monoalphabetic Caesar cipher of English, so the IoC approaches 0.0667 (English). Wrong key lengths mix different key letters, producing IoC closer to 0.0385 (random).
How does the tool recover each key letter?
For each key position, the corresponding column is extracted from the ciphertext. All 26 Caesar shifts are tried, and the chi-squared statistic is computed against English letter frequencies for each shift. The shift with the lowest chi-squared value is selected, because it makes the column's letter distribution most closely match English.
What is the minimum ciphertext length for reliable results?
The tool requires at least 20 letters but recommends 100 or more. With 100+ characters, the IoC values are stable and the chi-squared per column reliably identifies the correct shift. With fewer than 50 characters, the statistics are noisy and the solver may produce an incorrect key.
Can this tool solve autokey or running key ciphers?
No. Autokey and running key ciphers do not have a repeating key, so the IoC-based key length detection does not apply. The tool assumes a standard Vigenere cipher with a fixed repeating key. For autokey ciphers, different cryptanalytic methods are needed.
Why does the tool sometimes select a multiple of the true key length?
If the true key length is 4, the IoC will also be high at lengths 8, 12, and 16 (multiples of 4), because splitting by a multiple still groups characters encrypted with the same key letter. The tool selects the length with the highest IoC, which is usually the true key length, but with noisy data a multiple may win. Cross-check with the Kasiski Examination or Autocorrelation Cipher Detector.
Conclusion
Automated Vigenere cracking combines Friedman's Index of Coincidence for key length detection with chi-squared analysis for key letter recovery, reducing a 300-year-old cipher to a few seconds of computation. This tool implements the full attack with a step-by-step trace. For the Vigenere cipher itself, see the Vigenere Cipher. For manual cracking, use the Vigenere Cracker. For key length analysis tools, see the Kasiski Examination, Index of Coincidence, and Autocorrelation Cipher Detector.