StringMash.com

Substitution cipher decoder

Encode with a key, or crack one without it.

Conversion
14 characters
Updates as you type
CiphertextQzzqea qz rqvf
PlainA B C D E F G H I J K L M N O P Q R S T U V W X Y Z
CipherQ W E R T Y U I O P A S D F G H J K L Z X C V B N M

Show the steps
  1. Each letter of the alphabet is swapped for the key letter in the same position: A for the first, B for the second, and so on.

Solve one without the key

Works best on 100 letters or more.

Using it

With a key: type the 26-letter key, the cipher letters for A to Z in order, and encode or decode above. Without a key: paste the ciphertext into the solver and press Solve. The sample is the opening of Moby-Dick, encrypted with a key the page doesn't know.

The solver works best on 100 letters or more. On a short message a few rare letters may come out wrong; fix those by hand, the way you'd finish a crossword.

How the solver works

It guesses a key at random and scores the decryption by how English it looks: every run of four letters is checked against counts taken from three public-domain novels, so THER and TION score well and QXZK scores badly. Then it swaps two letters of the key and keeps the swap if the score goes up, over and over until nothing helps, and starts again from fresh guesses, keeping the best. It's the same frequency analysis people do by hand, done thousands of times a second.

The statistics are downloaded the first time you press Solve, as one file. Your ciphertext isn't sent anywhere.

Solving one by hand

Count the letters: in English, E, T, A, O, I and N are the most common. Look at one-letter words, which are almost always A or I, and three-letter words, where THE and AND are favourites. A repeated pattern like XYZZY might be a word with a double letter. Each letter you place makes the next one easier. The 9th-century scholar al-Kindi wrote the first known description of this method.

Questions

What's the difference between a substitution cipher and a cryptogram?

A cryptogram is a puzzle made with a substitution cipher, usually a quotation with the spaces left in. This solver handles them, and so does the cryptograms page if you'd rather solve them yourself.

Why didn't it solve my message?

It may be too short, or not a simple substitution: Vigenère and other polyalphabetic ciphers change the alphabet as they go. Try the cipher identifier first.

Does it work in other languages?

Its statistics are English, so it solves English text. A message in another language will come out as English-looking nonsense.

Sources

Added . What's new