A shift cipher was used to obtain the ciphertext kddkmu
. Decrypt it by trying all possibilities.
> allshifts("kddkmu")
"kddkmu"
"leelnv"
"mffmow"
"nggnpx"
"ohhoqy"
"piiprz"
"qjjqsa"
"rkkrtb"
"sllsuc"
"tmmtvd"
"unnuwe"
"voovxf"
"wppwyg"
"xqqxzh"
"yrryai"
"zsszbj"
"attack"
"buubdl"
"cvvcem"
"dwwdfn"
"exxego"
"fyyfhp"
"gzzgiq"
"haahjr"
"ibbiks"
"jccjlt"
As you can see, attack
is the only word that occurs on this list, so that was the plaintext.
Encrypt the plaintext message cleopatra
using the affine function
> affinecrypt("cleopatra", 7, 8)
"whkcjilxi"
The ciphertext mzdvezc
was encrypted using the affine function Decrypt it.
SOLUTION
First, solve for to obtain We need to find the inverse of
21
(On some computers, the doesn’t work. Instead, type a backslash and then Use the right arrow key to escape from the exponent before typing mod
. For some reason, a space is needed before a parenthesis in an exponent.)
Therefore, To change to standard form:
8
Therefore, the decryption function is To decrypt the message:
> affinecrypt("mzdvezc", 21, 8)
"anthony"
In case you were wondering, the plaintext was encrypted as follows:
> affinecrypt("anthony", 5, 12)
"mzdvezc"
Here is the example of a Vigenère cipher from the text. Let’s see how to produce the data that was used in Section 2.3 to decrypt it. For convenience, we’ve already stored the ciphertext under the name vvhq
.
> vvhq
vvhqwvvrhmusgjgthkihtssejchlsfcbgvwcrlryqtfsvgahwkcuhwauglqhnslrljs
hbltspisprdxljsveeghlqwkasskuwepwqtwvspgoelkcqyfnsvwljsniqkgnrgybwl
wgoviokhkazkqkxzgyhcecmeiujoqkwfwvefqhkijrclrlkbienqfrjljsdhgrhlsfq
twlauqrhwdmwlgusgikkflryvcwvspgpmlkassjvoqxeggveyggzmljcxxljsvpaivw
ikvrdrygfrjljslveggveyggeiapuuisfpbtgnwwmuczrvtwglrwugumnczvile
Find the frequencies of the letters in the ciphertext:
> frequency(vvhq)
[ 8, 5, 12, 4, 15, 10, 27, 16, 13, 14, 17, 25, 7, 7, 5, 9, 14, 17,
24, 8, 12, 22, 22, 5, 8, 5]
Let’s compute the coincidences for displacements of 1, 2, 3, 4, 5, 6:
> coinc(vvhq,1)
14
> coinc(vvhq,2)
14
> coinc(vvhq,3)
16
> coinc(vvhq,4)
14
> coinc(vvhq,5)
24
> coinc(vvhq,6)
12
We conclude that the key length is probably 5. Let’s look at the 1st, 6th, 11th, ... letters (namely, the letters in positions congruent to 1 mod 5):
> choose(vvhq, 5, 1)
"vvuttcccqgcunjtpjgkuqpknjkygkkgcjfqrkqjrqudukvpkvggjjivgjggpfncwuce"
> frequency(%)
[0, 0, 7, 1, 1, 2, 9, 0, 1, 8, 8, 0, 0, 3, 0, 4, 5, 2, 0, 3, 6, 5, 1, 0, 1, 0]
To express this as a vector of frequencies:
> vigvec(vvhq, 5, 1)
[0., 0., .1044776119, .01492537313, .01492537313,
.02985074627, .1343283582, 0., .01492537313, .1194029851,
.1194029851, 0., 0., .04477611940, 0., .05970149254,
.07462686567, .02985074627, 0., .04477611940, .08955223881,
.07462686567, .01492537313, 0., .01492537313, 0.]
The dot products of this vector with the displacements of the alphabet frequency vector are computed as follows:
> corr(%)
.02501492539, .03910447762, .07132835821, .03882089552,
.02749253732, .03801492538, .05120895523, .03014925374,
.03247761194, .04302985074, .03377611940, .02985074628,
.03426865672, .04456716420, .03555223882, .04022388058,
.04343283582, .05017910450, .03917910447, .02958208957,
.03262686569, .03917910448, .03655223881, .03161194031,
.04883582088, .03494029848
The third entry is the maximum, but sometimes the largest entry is hard to locate. One way to find it is
> max(%)
.07132835821
Now it is easy to look through the list and find this number (it usually occurs only once). Since it occurs in the third position, the first shift for this Vigenère cipher is by 2, corresponding to the letter A procedure similar to the one just used (using vigvec(vvhq, 5,2),..., vigvec(vvhq,5,5)
) shows that the other shifts are probably 14, 3, 4, 18. Let’s check that we have the correct key by decrypting.
> vigenere(vvhq, -[2, 14, 3, 4, 18])
themethodusedforthepreparationandreadingofcodemessagesissimpleinthe
extremeandatthesametimeimpossibleoftranslationunlessthekeyisknownth
eeasewithwhichthekeymaybechangedisanotherpointinfavoroftheadoptiono
fthiscodebythosedesiringtotransmitimportantmessageswithouttheslight
estdangeroftheirmessagesbeingreadbypoliticalorbusinessrivalsetc
For the record, the plaintext was originally encrypted by the command
> vigenere(%, [2, 14, 3, 4, 18])
vvhqwvvrhmusgjgthkihtssejchlsfcbgvwcrlryqtfsvgahwkcuhwauglqhnslrljs
hbltspisprdxljsveeghlqwkasskuwepwqtwvspgoelkcqyfnsvwljsniqkgnrgybwl
wgoviokhkazkqkxzgyhcecmeiujoqkwfwvefqhkijrclrlkbienqfrjljsdhgrhlsfq
twlauqrhwdmwlgusgikkflryvcwvspgpmlkassjvoqxeggveyggzmljcxxljsvpaivw
ikvrdrygfrjljslveggveyggeiapuuisfpbtgnwwmuczrvtwglrwugumnczvile