IA idea · Cryptography & number theory
Breaking a cipher with letter frequencies and chi-squared
Research question
How short can a message be before frequency analysis stops breaking a Caesar or affine cipher reliably, using a chi-squared statistic to score each possible key?
Make it yours, then agree it with your teacher.
Next step: plan this IA free — the planner opens with this question filled in. For feedback on your own draft, the IA package (€39 once) gives you 5 AI feedback credits and every annotated exemplar in full.
Why it makes a good exploration
Frequency analysis is a real attack with a real statistical core. Measuring how its success depends on message length turns a code-breaking game into a quantitative investigation.
The mathematics you'll need
- Letter frequencies from a large reference text
- Chi-squared statistic as a goodness-of-fit score
- Affine functions mod 26 and which keys are valid (counting)
- Proportion of successes against message length
- Fitting a model to the success curve
The statistics, step by step
Worked with every number shown, with what examiners look for and the common mistakes: Chi-squared goodness of fit. Then run the same steps on your own data in Analyse my data, or start from the statistics workflow.
Where the data comes from
Build reference frequencies from a public-domain book on Project Gutenberg; test on messages of different lengths from other texts.
- Project Gutenberg — 70,000+ free public-domain books as plain text — ideal for letter and word frequency counts.
- Desmos graphing calculator — Free graphing and regression (y₁ ~ ax₁ + b) — fit models to your data and show residuals.
Real data for this idea
- Primary source: Project Gutenberg: Free ebooks. Download two or three books as “Plain Text UTF-8” by hand and remove the licence header before counting. Licence: Public domain in the US; download a few books by hand (the site blocks bulk robots).
Links checked October 2026; we link to the data and never copy it. More free data sets.
A possible outline
- Explain the cipher and count the valid keys.
- Build reference frequencies.
- Score every key with chi-squared and pick the best.
- Test many messages of each length and record the success rate.
- Model the success rate and reflect on what makes short messages hard.
Pitfalls that cost marks
- Using chi-squared as a test with a p-value when it is really being used as a score; say which.
- Testing on the same text you built frequencies from.
- Too few messages per length.
Showing personal engagement
- Encrypt messages for friends and break theirs.
- Compare languages you speak.
- Find the shortest message you can still break.
See Criterion C: personal engagement for what examiners look for.
Which course is it for?
| Course | Fit | Maths to lean on |
|---|---|---|
| AA SL | Good fit | Letter frequencies from a large reference text; Chi-squared statistic as a goodness-of-fit score |
| AA HL | Fits, but add an HL technique | Letter frequencies from a large reference text; Chi-squared statistic as a goodness-of-fit score |
| AI SL | Good fit | Letter frequencies from a large reference text; Chi-squared statistic as a goodness-of-fit score |
| AI HL | Fits, but add an HL technique | Letter frequencies from a large reference text; Chi-squared statistic as a goodness-of-fit score |
Level: Accessible. A good first extended piece of maths, with room to go deeper. See how the IA differs between AA and AI, SL and HL.
How this idea reaches the top bands
Reflection (D)
For this idea, start with the weak points: using chi-squared as a test with a p-value when it is really being used as a score; say which; and testing on the same text you built frequencies from. Say how each one affects your answer.
Use of mathematics (E)
SL: letter frequencies from a large reference text; chi-squared statistic as a goodness-of-fit score; affine functions mod 26 and which keys are valid (counting); proportion of successes against message length; fitting a model to the success curve, each explained in your own words and carried out correctly.
How cryptography explorations reach the top bands in general: Cryptography & number theory IA ideas. Guides: A · B · C · D · E · self-grade sheet.
Taking it further
Attack a Vigenère cipher by splitting it into Caesar ciphers, or compare chi-squared with another score.
Extending it for HL
Add an HL technique the question genuinely needs: what an HL cryptography exploration adds.
See a complete IA, marked
Should I lease or buy my first car? (AI SL) is a complete cryptography exploration, marked on every criterion.
Frequently asked questions
Which IB Maths course is this IA idea for?
It works for AI SL, AA SL, AI HL and AA HL. We rate it Accessible: a good first extended piece of maths, with room to go deeper.
What mathematics does this IA use?
Letter frequencies from a large reference text, chi-squared statistic as a goodness-of-fit score, affine functions mod 26 and which keys are valid (counting), proportion of successes against message length and fitting a model to the success curve.
Where can I get data for this IA?
Build reference frequencies from a public-domain book on Project Gutenberg; test on messages of different lengths from other texts. Checked sources and tools: Project Gutenberg and Desmos graphing calculator.
Turn this idea into your IA
The planner opens with “Breaking a cipher with letter frequencies and chi-squared” filled in: the question, the maths and the data sources.
Your plan is kept in this browser. A free account keeps it with your drafts on any device: Join free · Sign in
Also: free IA self-check · A–E checklist (PDF) · have a draft? AI feedback or a review with Pete (€100)
Writing it up: how to write a Maths IA, step by step · structure and format · mistakes that cost marks · annotated exemplars, marked on every criterion
Similar ideas
- Finding the key length of a Vigenère cipher with the index of coincidenceAA HLAI HLAmbitious
- The Collatz conjecture: what can we say about stopping times?AA SLAA HLAI SLAI HLSolid
- How long would it take to guess your password? Counting and logarithmsAA SLAI SLAA HLAI HLAccessible
- How many primes are there below n? Testing the prime number theoremAA SLAA HLAI SLSolid
All cryptography ideas · AI SL ideas · AA SL ideas · AI HL ideas · AA HL ideas · All 239 IA ideas