Chapter 2
Classical cryptography

Much of the material below is based on Chapter 1 of Cryptography: theory and practice by Douglas R. Stinson.

2.1  The basic idea

The aim of cryptography is to enable two people, often called Alice and Bob, to communicate over an insecure channel so that an opponent Oscar cannot understand their messages.

These days the channel might be a telephone line, or a computer network. However cryptography has a long history. In the past the channel may have been a published book or a newspaper article (and the `opponent' would have been an ordinary reader), or the channel may have been a soldier carrying a concealed message with the opponent being the enemy army. Examples can be found in any introduction to cryptography, for example in the Code Book (see recommended reading), or in

Bill Cherowitzo's notes at the University of Colorado.

We call Alice's message plaintext. Let's say her message is x. Alice encrypts the message by applying one of a set of rules. The rule eK used depends on her choice of a secret key K. The encrypted message y=eK(x), which we call ciphertext, is sent over the insecure channel to Bob. Separately, by a secure channel Alice sends Bob her secret key K, which he will need to decipher Alice's message. When Bob receives the encrypted message y he decrypts the message by applying the decryption rule dK corresponding to the key K and retrieves Alice's plain text message x=dK(y). Meanwhile the opponent Oscar has intercepted the ciphertext y, but (ideally) without knowledge of the key K he is unable to understand it.

2.2  A simple cryptosystem

Pset of all possible plaintexts
Cset of all possible ciphertexts
Kset of all possible keys
For each key K Î K, there corresponds an encryption rule eK:P®C and a decryption rule dK:C®P. The rules eK and dK must have the properties listed in Table 2.1.

Property Reason
eK must be one-to-one if y=eK(x1)=eK(x2) with x1 ¹ x2 then Bob
would be unable to decrypt y
dK(eK(x))=x for each x Î Pto enable Bob to decipher all messages from Alice
if P=C then each eK is if the set of plaintexts and ciphertexts is identical
a permutation and dK is then each encryption rule eK just rearranges
the inverse permutation(permutes) the elements of this set.
Table 2.1: Properties of cryptosystems

Oscar's job is to find x, knowing y and without knowing the key K, but possibly knowing the type of encryption system used. This type of decryption is called cryptanalysis. We'll return to it later.

2.3  Shift ciphers

These form a family of ciphers based on modular arithmetic. One such cipher is reputed to have been used by Julius Caesar and is called the Caesar Cipher. Shift Ciphers, and the more general Affine Ciphers we'll meet later, are based on modular arithmetic. The basics of modular arithmetic are reviewed in Chapter 3.

Definition 1 (Shift Cipher) Let P=C=K=Z26. For 0 £ K £ 25, define eK:Z26®Z26 and dK:Z26®Z26 as follows (for x, y Î Z26).
eK(x)=x+K mod 26,    dK(y)=y-K mod 26

It is easy to see that each eK(x) is a one-to-one function, and that dK(eK(x))=x for all x Î Z26. Hence the Shift Cipher has the required properties for a cryptosystem.

The shift cipher with K=3 is the Caesar cipher.

We use Z26 because there are 26 letters in the English alphabet. Shift ciphers can be defined for any modulus m.

2.4  Using a Shift Cipher

For ordinary English text set up a correspondence between the alphabetic characters and the integers 0,...,25 as in Table 2.2.

ABCDEFGHIJKLM
0123456789101112
NOPQRSTUVWXYZ
13141516171819202122232425
Table 2.2: Correspondence of alphabet with Z26

A shift cipher with key K operates by `shifting each letter K places to the left'. We illustrate with a simple example.

Example 1 Encrypt the following plaintext with a Shift Cipher with key K=11.

agoodproofisonethatmakesuswiser
(This plaintext is a quote from A course in mathematical logic by Yu I. Manin, page 51.) Alice either constructs and uses a `look-up table' which goes directly from the plaintext to the ciphertext letters, as in Table 2.3,

ABCDEFGHIJKLM
LMNOPQRSTUVWX
NOPQRSTUVWXYZ
YZABCDEFGHIJK
Table 2.3: Plaintext to cipthertext with key K=11

or she proceeds as follows. She converts the plaintext to a sequence of integers using Table 2.2, obtaining:

06141431517141458181413419
701912010418201822818417

Next she adds 11 to each value, reducing the sum modulo 26.

1117252514022525161932524154
18114231121153537193152

Finally she converts the sequence of integers to alphabetic characters, obtaining the ciphertext.

LRZZOACZZQTDZYPESLEXLVPDFDHTDPC
To decrypt this message Bob will first convert the ciphertext to a sequence of integers, then subtract 11 from each value (reducing modulo 26), and finally he will convert the sequence of integers to alphabetic characters.

Conventions: We use lower case letters for plaintext and upper case letters for ciphertext. Often the spaces between words are removed.

Desirable properties for a cryptosystem:
It should be easy to encipher and decipher, that is, eK and dK should be efficiently computable.
It should be secure in the sense that, given the ciphertext, the opponent Oscar should be unable to find the key or the plaintext.

The Shift Cipher (modulo 26) is not secure. Oscar could conduct an exhaustive search by trying out all the possible 26 decryption rules dK in turn until he discovers a plaintext that makes sense.

Example 2 Given the ciphertext

IUJKHXKGQKXY
simply try out dK for all the keys K=0,1,...
iujkhxkgqkxy
htijgwjfpjwx
gshifvieoivw
frgheuhdnhuv
eqfgdtgcmgtu
dpefcsfblfst
codebreakers

until we find the plaintext. Here we find that the key was K=7 and the plaintext was `codebreakers'.

2.5  Substitution ciphers

For a general substitution cipher we require P=C, that is the same ciphertext and plaintext alphabet. In our examples we will take P to be the 26 letter alphabet and identify it with Z26. The set of keys K will be the set of all permutations of P. For a permutation p Î K, the rules ep and dp are
ep(x)=p(x),   and    dp(y)=p-1(y)
where p-1 is the inverse permutation of p, that is p-1(y)=x if and only if p(x)=y. The number of these permutations is 26! » 10×4.026, so an exhaustive key search is infeasible, even using a computer. (However other methods of cryptanalysis can be used to break a substitution cipher, see later.)

A shift cipher is a special type of substitution cipher, and there are only 26 of them. Another special type of substitution cipher is an Affine Cipher. This is one for which the encryption rule is
e(x)=ax+b mod 26
for some a,b Î Z26. To ensure that decryption is possible this function should be one-to-one (see Table 2.1). This happens if and only if gcd(a,26)=1 (see Lemma 3.3.0.1 in Chapter 3, and question 4 in Exercise Set 3.8). In Table 2.4 we give for easy reference a list of the multiplicative inverses for the 12 elements a Î Z26 for which gcd(a,26)=1.

a 135 7 911151719212325
a-1 192115319723115 1725
Table 2.4: Inverses in Z26

To decrypt the ciphertext y=e(x)=ax+b we need ax=y-b and hence x=a-1(y-b). Thus we must apply the decryption rule
d(y)=a-1(y-b).

Example 1 Encrypt the plaintext fun using an affine cipher with key K=(7,5) (that is, with encryption rule eK(x)=7x+5). Convert the letters f, u, n to residues modulo 26 using Table 2.2, and then apply eK and convert back to letters, againusing Table 2.2.


PlaintextxeK(x)Ciphertext
f 5 7·5+5=40=14 mod 26 O
u 207·20+5=145 = 15 mod 26P
n 137·13+5=96=18 mod 26S


Thus the encrypted message is OPS. Bob, knowing the key K=(7,5), decrypts this with the decryption rule dK(y)=15(y-5) (since 7-1=15).


CiphertextydK(y)Plaintext
O 14 15(14-5)=135=5 mod 26 f
P 1515(15-5)=150 = 20 mod 26u
S 1815(18-5)=195=13 mod 26n

Note that affine ciphers are not computationally secure as there are only 26·12 = 72 possible keys, and an exhaustive search by computer is feasible.

2.6  Polyalphabetic, block and stream ciphers

The ciphers described so far are all monoalphabetic ciphers, that is, for each occurrence of a given letter in the plaintext, the same cipher letter is used. A famous cipher that is not monoalphabetic is the Vigenere cipher named after Blaise de Vigenere who lived in the 16th century. The key K is a `keyword' of length m, for example K might be `wombat' of length m=6. We encrypt the plaintext 6 letters at a time by `adding the keyword to the plaintext'. Here is an example. From Table 2.2, the letters of the keyword `wombat' correspond to the numbers 22, 14, 12, 1, 0, 19. We write these out repeatedly under the numbers corresponding to the plaintext, add the result and convert to ciphertext using the correspondence in Table 2.2. We encrypt `Bring me chocolate' in this way as follows.


Plaintextbringmechocolate
x 1 178 136 124 2 714214110194
keyword 2214121 0 1922141210192214121
eK(x) 235 20146 5 01619152771455
Ciphertext X F U OGF AQ T P CH HOFF


To decrypt we follow essentially the same procedure, except that we `subtract the key word from the ciphertext' to regain the plaintext.


Using a keyword of length m, each plaintext letter x is mapped to one of m possible ciphertext letters. A cipher with this property is called polyalphabetic. Usually cryptanalysis is more difficult for polyalphabetic than monoalphabetic cryptosystems. For the Vigenere cipher, the number of possible keywords of length m is 26m, which is quite large even for small values of m; for m=6 this is more than 3×108. So for quite moderate keyword lengths, it becomes infeasible to search through all possible keywords.

In all ciphers considered so far, successive plaintext letters, or groups of letters, have been encrypted using the same key K, that is the ciphertext string y is obtained as y=y1y2... = eK(x1)eK(x2).... This type of cryptosystem is called a block cipher. For example, for a substitution cipher, each plaintext letter xi is encrypted with the single encryption rule eK to give a ciphertext letter yi=eK(xi). Thus a substitution cipher is a block cipher with blocks of length 1. On the other hand, for a Vigenere cipher with key word K=(k1,k2,...,km) of length m, m different encryption rules ek1,...,ekm are used for encrypting successive plaintext letters in each block of m plaintext letters, say x1,x2,...,xm is encrypted as ek1(x1),...,ekm(xm). We can think of this as a composite encryption rule eK being applied to the string producing eK(x1x2... xm), a ciphertext string of length m. Thus we think of the Vigenere cipher as being a block cipher with blocks of length m: we apply the same composite encryption rule eK to each block of length m of the plaintext.

We often want to send encrypted messages electronically and so we may wish to convert English symbols and numerals (whatever is in our normal plaintext alphabet) into strings of integers modulo 2 (that is, elements of Z2, also called binary integers or bits). For example, since there are 26=64 different bit strings of length 6, we would be able to assign a different bit string of length 6 to each of the 26 lower case letters, each of the 26 upper case letters, and each of the ten numerals, and still have two left over. Suppose we decided to group our plaintext into strings with five letters or numerals in each string, and to convert each letter or numeral into a bit string of length 6. Then we would have converted the plaintext into blocks each consisting of 30 bits. A cipher that encrypts these 30-bit strings block by block would be a block cipher with blocks of length 30. As far as the cipher is concerned the encryption key is acting on bit strings of length 30 and the plaintext alphabet P is the set of all 30-bit strings, so P contains 230 » 109 different elements (30-bit strings).

Currently the most commonly used block ciphers have blocks consisting of bit strings of length 64. This means that the plaintext alphabet has 264 elements! However 64 bit blocks are becoming insecure against modern computer cryptanalytic attack, and block ciphers are moving towards having blocks of 1024 or 2048 bits.

Historically there are several other block ciphers we could mention that use different ideas, and that have influenced future developments. One polyalphabetic cipher that encrypts the plaintext m letters at a time is the Hill Cipher, invented in 1929 by Lester S. Hill. It utilises linear algebra over Z26. The key K is an invertible m×m matrix with entries in Z26, and each string of m characters from the Plaintext is first converted to a sequence x of m numbers in Z26, so x Î Z26m. Then x is encrypted by multiplying by the matrix K: eK(x)=xK. The decryption rule is dK(y)=yK-1.

Another block cipher is the transposition cipher, sometimes also called the permutation cipher. For this cipher, the plaintext message is divided into blocks of a certain length m, and a permutation p is applied to rearrange the letters in each block. For example, if m=5 and
p = æ
è
1
2
3
4
5
3
1
4
5
2
ö
ø
   maps 1st letter ® 3rd place, 2nd letter® 1st place, etc
then we encrypt the plaintext `This is not secure' as:


Plaintext thisisnotsecure
CiphertextHITISNSSOTCEEUR


The transposition cipher can be decrypted by applying the inverse permutation p-1. The transposition cipher is not secure against cryptanalytic attack. However a combination of a substitution cipher followed by a transposition cipher results in a cipher that is more difficult to break by hand.

An alternative to block ciphers is to use what are called stream ciphers. A keystream is generated z=z1z2... and used to encrypt a Plaintext x=x1x2... by the rule y = ez1(x1)ez2(x2).... The keystream elements zi usually depend on the original key K and also on the preceding plaintext x1, x2,...,xi-1. This approach can be used to model mathematically many cryptosystems, including the one-time pad (see below).

Start with a key K Î K and the plaintext string x=x1x2.... For each i there is a rule (function) fi for generating the keystream element zi based on the key K and x1, x2,...,xi-1, that is,
zi=fi(K,x1, x2,...,xi-1).
We use zi to generate yi=ezi(xi). Thus we generate in order z1, y1, z2, y2,.... There must be a corresponding rule to allow `Bob' to find the zi and decrypt xi=dzi(yi), for each i.

Example 1 (a) A block cipher can be thought of as a special type of stream cipher by taking a constant keystream zi=K for all i.

(b) A stream cipher is periodic with period d if zi+d=zi for all i. The Vigenere cipher with key word of length m can be thought of as a periodic stream cipher with period m. In this case the keyword K=(k1,k2,...,km) gives the first m elements of the keystream z1=k1,...,zm=km, and the keystream just repeats itself from this point on. The encryption and decryption rules are simple: ez(x)=x+z, dz(y)=y-z.

(c) Stream ciphers are often defined with the plaintext, ciphertext, and keystream elements all being integers modulo 2 (bits). In this case
ez(x)=x+z mod 2, and dz(y)=y+z mod 2
so encryption and decryption are easy. If we think of 0 as `false' and 1 as `true' then addition mod 2 corresponds to the `exclusive-or' operation and can be implemented very efficiently in computer hardware.

(d) The case where the plaintext is a string of n integers mod 2, say x1x2... xn, and also the key K=(k1,k2,...,kn) is a string of the same length n of integers mod 2 is called the one-time pad. Here
eK(x1,x2,..., xn)=(x1+k1,x2+k2,...,xn+knmod 2, and 

dK(y1,y2,..., yn)=(y1+k1,y2+k2,...,yn+knmod 2.
This was described and patented by Gilbert Vernam in 1917. It is an unconditionally secure cryptosystem (provided the key is kept secret), and is important in military and diplomatic contexts. However it has limited use commercially because of key management problems: the key which must be communicated securely has length equal to the message length. Historical efforts in cryptography have been to design cryptosystems where one key can be used for many messages while maintaining (at least) computational security.


There are many other interesting `classical' ciphers. An excellent account can be found in the Code Book by Simon Singh. This includes stories about many of the ciphers used during World War II. Many books on classical cryptography can be found in the library. More recently a cipher called Solitaire involving a pack of cards for both encryption and decryption was suggested in the novel `Cryptonomicon' by Neal Stephenson. This cipher was developed by Bruce Schneier and a description can be found

on the Counterpane Internet Security web site.

2.7  Cryptanalysis

The golden rule for designers of cryptosystems is never to underestimate the cryptanalyst.



Kerckhoff's Principle 1883: Assume that the cryptanalyst (opponent) knows the cryptosystem.



It would be unwise to design a cryptosystem without assuming Kerckhoff's Principle. The goal is to achieve security while observing it. There are different levels of attack on cryptosystems and the most common ones are listed in Table 2.5. The objectis always to determine the key K. The `chosen ciphertext attack' is in particular relevant to public-key cryptosystems, which we discuss later.

Type Description
Ciphertext only The opponent possesses a string of ciphertext y.
Known plaintextThe opponent possesses a string of plaintext x and the
corresponding ciphertext y.
Chosen plaintextThe opponent has obtained temporary access to the
encryption machinery; has chosen a string of plaintext x
and constructed the corresponding ciphertext string y.
Chosen ciphertextThe opponent has obtained temporary access to the
decryption machinery; has chosen a string of ciphertext y
and constructed the corresponding plaintext string x.
Table 2.5: Types of cryptanalytic attack



Consider the weakest type of attack, the `ciphertext only attack'. Assume that the plaintext is English or some other structured language. Then a frequency count will give good guesses for the commonly occurring letters: simply work out the frequency of commonly occurring letters in the ciphertext and compare these against the English frequency statistics, see Table 2.6, to guess what they stand for in the plaintext. The rest can be broken by the redundancy naturally present in English. (The data in Table 2.6is from Beker and Piper, p.397.)

From Table 2.6, the most commonly occurring letters in English are, in order, E T A O I N S R H ¼. Also the most common pairs are TH, HE, IN, ER, AN, RE ¼, and the most common triples are THE, AND, ING, ION. You have an opportunity to try this out in a simple way with the last question in the Exercise Set on Classical Ciphers.

letterprobability letter occurrence
A.082N.067
B.015O.075
C.028P.019
D.043Q.001
E.127R.060
F.022S.063
G.020T.091
H.061U.028
I.070V.010
J.002W.023
K.008X.001
L.040Y.020
M.024Z.001
Table 2.6: Probability of occurrence of the 26 letters

2.8  Exercise Set: Classical Ciphers

1. Encrypt the following using a Shift Cipher with key K=4.

logic is the youth of mathematics
[Quote from Bertrand Russell]


2. The following was encrypted using a Shift Cipher. Decrypt it. What was the key?

OLIHLVQRWDSUREOHPLWLVDPBVWHUBWREHXQIXUOHG


3. Show that the ciphertext of dog using an affine cipher with key K=(3,9) is YXT.


4. Decrypt the ciphertext YATJ if an affine cipher with key K=(11,2) was used for encryption.


5. Decrypt the ciphertext

UWTULFPTZKFHBZMZIM
given that it has been encrypted with the Vigenere cipher using the keyword `maths'.


6. Below are given three examples of ciphertext, each obtained from either a shift cipher or an affine cipher. In each case determine what type of cipher was used, and find the key. If you have the energy find the plaintext. I have left in the punctuation and spaces between words to make it easier. (With one of them, you may need to `decipher' it further after decryption.)


6A Y SYQR WYXRWJ AG DUXRWJ OJ AG AOXRWJ, OJ YHPWWP BOXR OD XRWA, UQ XRWG SWJW YH PEXG BOXR WCEUTTG BOEHP XO YX, RUP AYHPWP SRUX XRWG SWJW UBOEX SRWH XRWG BWKOX AW; RUP XRWG PETG IOHQYPWJ'P ROS AEIR PWVWHPWP EVOH SRUX XRWG SWJW XRWH POYHK;-XRUX HOX OHTG XRW VJOPEIXYOH OD U JUXYOHUT BWYHK SUQ IOHIWJHWP YH YX, BEX XRUX VOQQYBTG XRW RUVVG DOJAUXYOH UHP XWAVWJUXEJW OD RYQ BOPG, VWJRUVQ RYQ KWHYEQ UHP XRW LWJG IUQX OD RYQ AYHP;-UHP, DOJ UEKRX XRWG MHWS XO XRW IOHXJUJG, WLWH XRW DOJXEHWQ OD RYQ SROTW ROEQW AYKRX XUMW XRWYJ XEJH DJOA XRW REAOEJQ UHP PYQVOQYXYOHQ SRYIR SWJW XRWH EVVWJAOQX;-RUP XRWG PETG SWYKRWP UHP IOHQYPWJWP UTT XRYQ, UHP VJOIWWPWP UIIOJPYHKTG,-Y UA LWJYTG VWJQEUPWP Y QROETP RULW AUPW U CEYXW PYDDWJWHX DYKEJW YH XRW SOJTP, DJOA XRUX YH SRYIR XRW JWUPWJ YQ TYMWTG XO QWW AW.-BWTYWLW AW, KOOP DOTMQ, XRYQ YQ HOX QO YHIOHQYPWJUBTW U XRYHK UQ AUHG OD GOE AUG XRYHM YX;-GOE RULW UTT, Y PUJW QUG, RWUJP OD XRW UHYAUT QVYJYXQ, UQ ROS XRWG UJW XJUHQDEQWP DJOA DUXRWJ XO QOH, WXI. WXI.-UHP U KJWUX PWUT XO XRUX VEJVOQW:-SWTT, GOE AUG XUMW AG SOJP, XRUX HYHW VUJXQ YH XWH OD U AUH'Q QWHQW OJ RYQ HOHQWHQW, RYQ QEIIWQQWQ UHP AYQIUJJYUKWQ YH XRYQ SOJTP PWVWHP EVOH XRWYJ AOXYOHQ UHP UIXYLYXG, UHP XRW PYDDWJWHX XJUIMQ UHP XJUYHQ GOE VEX XRWA YHXO, QO XRUX SRWH XRWG UJW OHIW QWX U-KOYHK, SRWXRWJ JYKRX OJ SJOHK, 'XYQ HOX U RUTD- VWHHG AUXXWJ,-USUG XRWG KO ITEXXWJYHK TYMW RWG-KO AUP; UHP BG XJWUPYHK XRW QUAW QXWVQ OLWJ UHP OLWJ UKUYH, XRWG VJWQWHXTG AUMW U JOUP OD YX, UQ VTUYH UHP UQ QAOOXR UQ U KUJPWH-SUTM, SRYIR, SRWH XRWG UJW OHIW EQWP XO, XRW PWLYT RYAQWTD QOAWXYAWQ QRUTT HOX BW UBTW XO PJYLW XRWA ODD YX.


VJUG AG PWUJ, CEOXR AG AOXRWJ, RULW GOE HOX DOJKOX XO SYHP EV XRW ITOIM?- KOOP K..! IJYWP AG DUXRWJ, AUMYHK UH WZITUAUXYOH, BEX XUMYHK IUJW XO AOPWJUXW RYQ LOYIW UX XRW QUAW XYAW,-PYP WLWJ SOAUH, QYHIW XRW IJWUXYOH OD XRW SOJTP, YHXWJJEVX U AUH SYXR QEIR U QYTTG CEWQXYOH? VJUG, SRUX SUQ GOEJ DUXRWJ QUGYHK?-HOXRYHK.


6B XQNGPGNC

SYTU DGS GVNY NDU KQV --  
AUVNPC GNK NYQOD IWYMU DGS YVOU,  
IN DYSU, WDGKBUHGVA YX XGUPRK QVKYWV. 
IPWICK GN WYMU DGS, UTUV GV XHIVOU,   
QVNGP NDGK SYHVGVA IVR NDGK KVYW. 
GX IVCNDGVA SGADN HYQKU DGS VYW   
NDU MGVR YPR KQV WGPP MVYW.   

NDGVM DYW GN WIMUK NDU KUURK --   
WYMU, YVOU, NDU OPICK YX I OYPR KNIH. 
IHU PGSLK KY RUIH-IODGUTUR, IHU KGRUK 
XQPP-VUHTUR, -- KNGPP WIHS, -- NYY DIHR NY KNGH?  
WIK GN XYH NDGK NDU OPIC AHUW NIPP?   
-- Y WDIN SIRU XINQYQK KQVLUISK NYGP  
NY LHUIM UIHND'K KPUUB IN IPP?


6C GJJXKYY ZU G NGMMOY

LGOX LG' EUAX NUTKYZ, YUTYOK LGIK,  
MXKGZ INOKLZGOT U' ZNK VAJJOTM-XGIK! 
GHUUT ZNKS G' EKZ ZGQ EUAX VRGIK, 
VGOTIN, ZXOVK, UX ZNGOXS:  
CKKR GXK EK CUXJE U'G MXGIK 
GY RGTM'Y SE GXS.  
 
ZNK MXUGTOTM ZXKTINKX ZNKXK EK LORR, 
EUAX NAXJOKY ROQK G JOYZGTZ NORR, 
EUAX VOT CGY NKRV ZU SKTJ G SORR  
OT ZOSK U'TKKJ,  
CNORK ZNXU' EUAX VUXKY ZNK JKCY JOYZOR 
ROQK GSHKX HKGJ. 
 
NOY QTOLK YKK XAYZOI RGHUAX JOMNZ,  
GT' IAZ EUA AV CO' XKGJE YRKOMNZ, 
ZXKTINOTM EUAX MAYNOTM KTZXGORY HXOMNZ,  
ROQK UTE JOZIN;  
GTJ ZNKT, U CNGZ G MRUXOUAY YOMNZ,  
CGXS-XKKQOT', XOIN! 
 
ZNKT, NUXT LUX NUXT, ZNKE YZXKZIN GT' YZXOBK: 
JKOR ZGQ ZNK NOTJSUYZ! UT ZNKE JXOBK,  
ZORR G' ZNKOX CKKR-YCGRR'J QEZKY HKREBK  
GXK HKTZ ROQK JXASY;  
ZNKT GARJ MAOJSGT, SGOYZ ROQK ZU XOBK, 
HKZNGTQOZ! NASY. 
 
OY ZNKXK ZNGZ UCXK NOY LXKTIN XGMUAZ 
UX UROU ZNGZ CGJ YZGC G YUC,  
UX LXOIGYYKK CGJ SGQK NKX YVKC  
CO' VKXLKIZ YIUTTKX,  
RUUQY JUCT CO' YTKKXOTM, YIUXTLA' BOKC 
UT YOI G JOTTKX? 
 
VUUX JKBOR! YKK NOS UCXK NOY ZXGYN, 
GY LKIQRKY GY COZNKX'J XGYN,  
NOY YVOTJRK YNGTQ, G MAOJ CNOV-RGYN; 
NOY TOKBK G TOZ; 
ZNXU' HRUJE LRUUJ UX LOKRJ ZU JGYN, 
U NUC ATLOZ! 
 
HAZ SGXQ ZNK XAYZOI, NGMMOY-LKJ,  
ZNK ZXKSHROTM KGXZN XKYUATJY NOY ZXKGJ.  
IRGV OT NOY CGROK TOKBK G HRGJK,  
NK'RR SGQ OZ CNOYYRK; 
GT' RKMY GT' GXSY, GT' NGTJY CORR YTKJ,  
ROQK ZGVY U' ZXOYYRK. 
 
EK VUC'XY, CNG SGQ SGTQOTJ EUAX IGXK,  
GTJ JOYN ZNKS UAZ ZNKOX HORR U' LGXK,  
GARJ YIUZRGTJ CGTZY TGK YQOTQOTM CGXK  
ZNGZ PGAVY OT RAMMOKY;  
HAZ, OL EK COYN NKX MXGZKLA' VXGEKX 
MOK NKX G NGMMOY!

2.9  Exercise Solutions: Classical Ciphers

1.  PSKMGMWXLICSYXLSJQEXLIQEXMGW


2. Life is not a problem. It is a mystery to be unfurled. The key was K=3.


3.


PlaintextxeK(x)Ciphertext
d 3 7·3+3=24 mod 26 Y
o 147·14+3=101 = 23 mod 26X
g 6 7·6+3=45 = 19 mod 26T


4. Since 11-1=19 in Z26, dK(y)=19(y-2). We decrypt as in the table below and find the plaintext `cold'.


CiphertextydK(y)Plaintext
Y 24 19(24-2)=418 = 2 mod 26 c
A 0 19( 0-2)=-38=14 mod 26 o
T 19 19(19-2)=323=11 mod 26 l
J 9 19( 9-2)=133 = 3 mod 26 d


5. The keyword `maths' corresponds to the sequence 12, 0, 19, 7, 18. We therefore decrypt as follows.



CiphertextUWTULFPTZKFHBZ
y 2022192011515 19251057 1 25
keyword 120197 1812019718120197
dK(y) 8 220 131919150 1818197 8 18
Plaintextiw a n tt pa ss t h i s

MZIM
1225812
1812019
2013819
u n it


Plaintext: I want to pass this unit.


6A. This used an affine cipher eK:x® ax+b with a=7, b=20 modulo 26. The plaintext is from the first chapter of Tristan Shandy by Lawrence Stern.


I wish either my father or my mother, or indeed both of them, as they were in duty both equally bound to it, had minded what they were about when they begot me; had they duly consider'd how much depended upon what they were then doing;-that not only the production of a rational Being was concerned in it, but that possibly the happy formation and temperature of his body, perhaps his genius and the very cast of his mind;-and, for aught they knew to the contrary, even the fortunes of his whole house might take their turn from the humours and dispositions which were then uppermost;-Had they duly weighed and considered all this, and proceeded accordingly,-I am verily persuaded I should have made a quite different figure in the world, from that in which the reader is likely to see me.-Believe me, good folks, this is not so inconsiderable a thing as many of you may think it;-you have all, I dare say, heard of the animal spirits, as how they are transfused from father to son, etc. etc.-and a great deal to that purpose:-Well, you may take my word, that nine parts in ten of a man's sense or his nonsense, his successes and miscarriages in this world depend upon their motions and activity, and the different tracks and trains you put them into, so that when they are once set a-going, whether right or wrong, 'tis not a half- penny matter,-away they go cluttering like hey-go mad; and by treading the same steps over and over again, they presently make a road of it, as plain and as smooth as a garden-walk, which, when they are once used to, the Devil himself sometimes shall not be able to drive them off it.


Pray my Dear, quoth my mother, have you not forgot to wind up the clock?- Good G..! cried my father, making an exclamation, but taking care to moderate his voice at the same time,-Did ever woman, since the creation of the world, interrupt a man with such a silly question? Pray, what was your father saying?-Nothing.


6B. This used an affine cipher eK:x® ax+b with a=3, b=8 modulo 26. The plaintext is a poem by Wilfred Owen.

Futility

Move him into the sun --
Gently its touch awoke him once,
At home, whispering of fields unsown.
Always it woke him, even in France,
Until this morning and this snow.
If anything might rouse him now
The kind old sun will know.

Think how it wakes the seeds --
Woke, once, the clays of a cold star.
Are limbs so dear-achieved, are sides
Full-nerved, -- still warm, -- too hard to stir?
Was it for this the clay grew tall?
-- O what made fatuous sunbeams toil
To break earth's sleep at all?


6C. This used a shift cipher eK:x® x+6. The plaintext is a poem by Robert Burns.

Address To A Haggis

Fair fa' your honest, sonsie face,
Great chieftain o' the pudding-race!
Aboon them a' yet tak your place,
Painch, tripe, or thairm:
Weel are ye wordy o'a grace
As lang's my arm.

The groaning trencher there ye fill,
Your hurdies like a distant hill,
Your pin was help to mend a mill
In time o'need,
While thro' your pores the dews distil
Like amber bead.

His knife see rustic Labour dight,
An' cut you up wi' ready sleight,
Trenching your gushing entrails bright,
Like ony ditch;
And then, O what a glorious sight,
Warm-reekin', rich!

Then, horn for horn, they stretch an' strive:
Deil tak the hindmost! on they drive,
Till a' their weel-swall'd kytes belyve
Are bent like drums;
Then auld Guidman, maist like to rive,
Bethankit! hums.

Is there that owre his French ragout
Or olio that wad staw a sow,
Or fricassee wad make her spew
Wi' perfect sconner,
Looks down wi' sneering, scornfu' view
On sic a dinner?

Poor devil! see him owre his trash,
As feckles as wither'd rash,
His spindle shank, a guid whip-lash;
His nieve a nit;
Thro' blody flood or field to dash,
O how unfit!

But mark the Rustic, haggis-fed,
The trembling earth resounds his tread.
Clap in his walie nieve a blade,
He'll mak it whissle;
An' legs an' arms, an' hands will sned,
Like taps o' trissle.

Ye Pow'rs, wha mak mankind your care,
And dish them out their bill o' fare,
Auld Scotland wants nae skinking ware
That jaups in luggies;
But, if ye wish her gratefu' prayer
Gie her a haggis!


Cheryl E. Praeger
File translated from TEX by TTH,version 3.
On Sat Oct 27 09:46:31 2001.

Contents

1  Introduction
    1.1  CODES
    1.2  CIPHERS
2  Classical cryptography
    2.1  The basic idea
    2.2  A simple cryptosystem
    2.3  Shift ciphers
    2.4  Using a Shift Cipher
    2.5  Substitution ciphers
    2.6  Polyalphabetic, block and stream ciphers
    2.7  Cryptanalysis
    2.8  Exercise Set: Classical Ciphers
    2.9  Exercise Solutions: Classical Ciphers
3  Modular Arithmetic
    3.1  Arithmetic mod n
    3.2  GCD's
    3.3  Inverses and Euler's phi function
    3.4  Polynomials
    3.5  Finite fields
    3.6  Fermat and Euler
    3.7  Vector spaces
    3.8  Exercise Set: Modular arithmetic
    3.9  Solutions: ModArith
4  Linear Feedback Shift Registers
    4.1  Keystreams
    4.2  Primitive polynomials
    4.3  Randomness
    4.4  Exercise Set: LFSR's
    4.5  Solutions: LFSR's
5  Data Encryption Standard
    5.1  Secret key cryptography
    5.2  DES
    5.3  Modes of operation
    5.4  The DES Controversy
    5.5  Uses of DES
    5.6  Modern developments
6  Public Key Cryptosystems
    6.1  Public keys
    6.2  One-way functions
    6.3  The RSA cryptosystem
    6.4  Primes and factorisation
    6.5  Some related topics
    6.6  Exercise Set: Public Key Cryptography
    6.7  Exercise Solutions: Public Key Cryptography
7  Information Theory
    7.1  Redundancy
    7.2  Information and uncertainty
    7.3  Entropy
    7.4  Exercise Set: Information Theory
    7.5  Exercise Solutions: Information Theory
8  Codes: an introduction
    8.1  Block codes
    8.2  ISBN Numbers
    8.3  ASCII code
    8.4  Hamming distance
    8.5  Maximum likelihood
    8.6  Exercise Set: Codes I
    8.7  Exercise Solutions: Codes I
9  Linear Codes
    9.1  Linear (n,k) codes
    9.2  Dual Codes
    9.3  Parity check matrices
    9.4  Information about Hamming distance
    9.5  Exercise Set: Codes II
    9.6  Ex. Solns: Codes II
10  Families of codes and perfect codes
    10.1  Hamming codes
    10.2  Perfect codes and the Sphere Packing Bound
    10.3  Golay codes
    10.4  The (r+1,r) parity check code.
    10.5  Repetition codes
    10.6  Hadamard codes
11  Decoding with parity check matrices
    11.1  The Set-up
    11.2  Cosets of codes
    11.3  Syndromes
12  In the News
    12.1  E-books
    12.2  The Cayley-Purser algorithm
13  Assignments and Test
    13.1  Assignment 1: Cryptography
    13.2  Assignment 1 SOLUTIONS
    13.3  Assignment 2: Public key Cryptography and Codes
    13.4  Assignment 2 SOLUTIONS
    13.5  Test: 3CC
    13.6  Test Solutions
    13.7  2001 Sample Exam