Thursday, 18 October 2012

A fine cipher!

As part of the National Cipher Challenge one of the student Codebreakers, Megan, independently cracked the new codes by realising that it was enciphered as an 'Affine Cipher'

Megan looked up how Affine Ciphers worked so that she could crack it.
She wrote up a great guide to what an Affine cipher is and how to use one...



Affine Ciphers

The Affine Shift Cipher is a special type of substitution cipher, similar to that of the Caesar Shift Cipher. However, instead of just ‘shifting’ all the letters by a certain amount, we must first convert each letter into a number, as shown below:

A
B
C
D
E
F
G
H
I
J
K
L
M
0
1
2
3
4
5
6
7
8
9
10
11
12
 
 
 
 
 
 
 
 
 
 
 
 
 
N
O
P
Q
R
S
T
U
V
W
Z
Y
Z
13
14
15
16
17
18
19
20
21
22
23
24
25


We then apply a function to the letter which you had converted into a number, in the form ax + b, where x is the number of the letter and a and b are constant amounts which we apply to every number.


For example, lets try coding the word BEACH, by using the function 3x +2. (i.e. a = 3 and b = 2, where x is the number of each letter).
So lets start with B, which we can convert into the number 1. 
We then input this into the equation 3x + 2.
3(1) + 2 = 5
We then convert this number back into a letter, using the same key as above.
5 = F
So the letter B has transformed into the letter F.
We then do the same thing for each of the other letters.
E = 4 à  3(4) + 2 = 14 à 14 = O
A = 0 à  3(0) + 2 = 2  à  2 = C
C = 2 à 3(2) + 2 = 8   à  8 = I
H = 7 à 3(7) + 2 = 23 à 23 = Z.

So the coded message of BEACH when applying the function 3x + 2 is FOCIZ"

After Megan worked out what Affine ciphers were she then cracked the new code. Read Megan's account of how she cracked it...


In the code, only 2 letters were ever on their own - L and Z. So i assumed they were a and i.
L = 11
Z = 25
a = 0
i = 8

So i thought, if L = a, then b would have to equal 11. (ax0(because a = 0)+11 = 11 (which = L)
So then if Z = i, the equation would be 8a + 11 = 25 (mod 26)
So then I tried inputting numbers 1,2,3,4 etc up to 25... it was annoying because I kept making mistakes... then (after 13 was kinda working but not properly) remembered that when i had first looked up the affine shift cypher it said it could only be 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25 (which i realised obviously made sense cuz else you wouldn't be able to get all the letters because the others are factors of 26). So then i started again from 3, and then i did 5 and it worked (I'd obviously made a mistake last time). 8 x 5 + 11 = 25! So then i thought 'oh hey, a (in the equation) must equal 5!'
(^ ^ if this hadn't worked I would have tried L = i and Z = a, but thankfully it did)



So then i found this website where you could put in the code and what a and b equal and it would decode it for you. It showed me i was right (thankfully! I'd already tried a few combos and they had failed) however, it didn't leave spaces between words... so...
Then I went on the Simon Singh website and found this 'black chamber' thing. I put in L = a and Z = i, and then worked out the other letters by matching them up using the website I used before or subbed the numbers of the letters into 5x+11. I also used the frequency thing which was cool (useful for the most common letters like e)


Megan's method of cracking this code mirrors exactly how modern codebreakers try to crack codes...using some intuition, reading up on how some codes work and a fair bit of work!

2 comments:

  1. N'aww, what a good student, gold form?

    ReplyDelete
    Replies
    1. Certainly, and well deserved don't you think?

      Delete