An experiment in statistical decryption of simple substitution ciphers

When people put up an encrypted text puzzle online it is frequently a simple substitution cipher whereby each letter stands for a different letter and the plaintext is revealed by discovering the correct replacements for each letter. I always wondered if it was possible to automatically decrypt these puzzles by analyzing the frequency with which each character appears and compare that to the frequency of each character in the english language. (Obviously I’m only decrypting english text, otherwise how would I know when it’s right? Regardless, this code will work equally well for any language.) Recently I decided to test the theory. The code is after the jump.

Continue reading