Hacking Secret Ciphers with Python

(Ann) #1

300 http://inventwithpython.com/hacking


Email questions to the author: [email protected]


A coin has 2 sides, and when you flip a coin, about half the time it will come up heads and half of
the time it comes up tails. The frequency (that is, how often) that the coin flip ends up heads is
the same as the frequency that it ends up tails: about one-half or 50%.


There are 26 letters in the English alphabet, but they don’t each appear an equal amount of the
time in English text. Some letters are used more often than others. For example, if you look at the
letters in this book you will find that the letters E, T, A and O occur very frequently in English
words. But the letters J, X, Q, and Z are rarely found in English text. We can use this fact to help
crack Vigenère-encrypted messages. This technique is called frequency analysis.


Here are the frequencies of the 26 letters in average English text. This graph is compiled by
grabbing English text from books, newspapers, and other sources to count often each letter
appears:


Figure 20-1. Letter frequency of normal English.

If we sort these in order of greatest frequency to least, we find that E is the most frequent letter,
followed by T, followed by A, and so on:

Free download pdf