## Demo: Breaking Caesar Cipher Via Frequency Counting

Either choose a shift value and enter some plaintext (then press enter), in which case the app will simply encrypt for you, or enter some ciphertext (then press enter) in which case the app will use frequency analysis to decrypt for you. To reset the app, press shift and click on your browser's refresh button.
plaintextshiftciphertext
letterfrequency
in English
frequency
in ciphertext
a8.167
b1.492
c2.782
d4.253
e12.702
f2.228
g2.015
h6.094
i6.966
j0.153
k0.772
l4.025
m2.406
n6.749
o7.507
p1.929
q0.095
r5.987
s6.327
t9.056
u2.758
v0.978
w2.360
x0.150
y1.974
z0.074

 most likely shift index - probability of this index - times more likely than the next best -

Explanation

Caesar shift encryption encrypts a message by replacing each character with the character x places further down in alphabetical order (wrapping back to the top if needed). The number x, called the shift index, is a secret key to be shared between the two communicating parties. The possible shift indices are 0-25, though a shift index of 0 is not a great idea, since it leaves the message unchanged! Cracking a Caesar shift encrypted message boils down to figuring out the shift index.

The letter e is the most common character in English text. If you noticed that h was the most common character in the ciphertext, you might guess that h is what the letter e got shifted too, and deduce that the shift index is three. The idea of cryptanalysis by frequency analysis just makes that idea more systematic. In this demo, we use the English letter frequencies given in the table to the left, and the letter frequencies we observe in the ciphertext and deduce the most likely shift index in the following way: For each possible shift index i, we construct the plaintext that would result from shift index i, and compute how likely that plaintext would be given the English letter frequencies. Whichever shift produced the highest likelihood is our best guess.