Lion Cipher Lab
Break a classical cipher with frequency analysis (and learn why modern crypto is different)
- Foundations
- Beginner
- ~45 min
- Free · no account required
Why it matters
Almost everything you do online is protected by cryptography -- the padlock in your browser, your messages, your passwords at rest. To trust it, it helps to first see a cipher BREAK, and to understand why. For roughly two thousand years, the best secret-writing anyone had was a classical cipher: shift every letter along the alphabet (a Caesar cipher), or swap each letter for some other fixed letter (a substitution cipher). They feel unbreakable -- a substitution has about four hundred trillion trillion possible keys, a number you could not brute-force before the heat death of the universe.…
What you'll learn
- understanding what a cipher, plaintext, ciphertext, and key actually are, in plain language, by building and breaking one yourself
- writing a letter-frequency counter in a few lines of pure Python using collections.Counter and the string module -- no libraries to install
- breaking a Caesar shift cipher automatically with a chi-squared test: scoring all 26 possible shifts against English letter frequencies and picking the one that fits best, recovering the key without being told it
- stepping up to a full monoalphabetic substitution cipher and recovering the exact plaintext with letter frequencies plus common letter-pair/triple statistics, even though its key space (26 factorial, about 4x10^26) is far too large to brute-force
- seeing the honest limit of the technique first-hand: frequency analysis fails on very short ciphertext because the statistics have not converged, which teaches why sample size matters
- carrying the one rule that falls straight out of the exercise -- a cipher whose output still shows the shape of its input is already broken -- and why that means 'never roll your own crypto; use vetted standards like AES'
Steps in this lab
- The handful of words you need first
- Set up, and save the Caesar program
- Run it: watch an unreadable message read itself
- Why chi-squared is the right judge
- The honest catch: too few letters and it fails
- Step up: a full substitution and its 400 trillion trillion keys
- Run it: the enormous key space falls anyway
- Why modern crypto is built differently -- and the two laws behind it
- When classical ciphers are still worth knowing -- and when they are never OK
- What you built, and the reflex to keep