Pages

Wednesday 11 December 2013

Breaking Substitution Ciphers Part 1

The 'Substitution cipher' is a fairly well known algorithm for enciphering text, a good description of which can be found here. It is also fairly well known that they can be fairly easily broken using hill climbing approaches.

In this post I'm going to look at a different method of breaking substitution ciphers which is not so dependent on trying lots of different cases until one works. The problem with that approach is that you can't be sure how long your cracker will need to run, perhaps by leaving it a bit longer it will eventually succeed? So I'll treat the sentence somewhat like a HMM, then try and find the most likely sequence of characters that make up the key. This will require relaxing some of the constraints, in this case we will relax the constraint that a ciphertext letter will always decrypt to the same plaintext letter. At the end we'll try and massage everything back into place so that we have the most likely decryption key.

Building the Lattice

Our first task is to build the lattice over which we will be doing all our work, our test sentence will be DEFEND THE EAST enciphered to GIUIFGCEIIPRC. This is a very short sentence which will probably not break due to its length, but hopefully it will illustrate the technique which can be applied to longer sentences.

Our first step is to determine emission probabilities. e.g. G is the first letter of the ciphertext, what is the probability that ciphertext G decrypts to plaintext A? or B? This question will be answered using the multinomial distribution and the counts for each letter. In this case G occurs twice in 13 letters, and we know that A occurs with a frequency of 0.0855. This means the probability of ciphertext G corresponding to plaintext A can be computed as follows:

\[ p(G_{CT} = A_{PT}) = \dfrac{n_{TOT}!}{n_A!~n_{\lnot A}!}p(A)^{n_A}p(\lnot A)^{n_{\lnot A}}\] \[= \dfrac{13!}{2!11!}0.0855^2 \times (1-0.0855)^{11} = 0.2133\]

In the equation above I have simplified the formula a bit by assuming \(x_1\) is the number of times A occurs, and \(x_2\) is the number of times all other characters occur. We then have to repeat this computation for all plaintext characters, for example the probability that G is B is 0.0167, so it is more likely that G decrypts to A than B.

By applying the formula above for every plaintext letter and each ciphertext letter we get a 'lattice' of size \(n\times 26\). It will look something like the following, note that each column has been normalised to sum to 1:

GIUIFGCEIIPRC
A0.1000.1250.0610.1250.0610.1000.1000.0610.1250.1250.0610.0610.100
B0.0080.0000.0280.0000.0280.0080.0080.0280.0000.0000.0280.0280.008
C0.0260.0040.0450.0040.0450.0260.0260.0450.0040.0040.0450.0450.026
D0.0360.0080.0500.0080.0500.0360.0360.0500.0080.0080.0500.0500.036
E0.1300.3500.0540.3500.0540.1300.1300.0540.3500.3500.0540.0540.130
F0.0140.0010.0350.0010.0350.0140.0140.0350.0010.0010.0350.0350.014
..........................................
W0.0100.0000.0310.0000.0310.0100.0100.0310.0000.0000.0310.0310.010
X0.0000.0000.0040.0000.0040.0000.0000.0040.0000.0000.0040.0040.000
Y0.0090.0000.0290.0000.0290.0090.0090.0290.0000.0000.0290.0290.009
Z0.0000.0000.0020.0000.0020.0000.0000.0020.0000.0000.0020.0020.000

This post is ongoing, I will edit it some more when I get a chance.

No comments:

Post a Comment