Korner - Coding and Cryptography
Korner - Coding and Cryptography
Transmitting messages across noisy channels is an important practical problem. Coding theory provides explicit ways of ensuring that messages remain legible even in the presence of errors. Cryptography on the other hand, makes sure that messages remain unreadable | except to the intended recipient. These complementary techniques turn out to have much in common mathematically.
Small print The syllabus for the course is de ned by the Faculty Board Schedules (which are minimal for lecturing and maximal for examining). I should very much appreciate
being told of any corrections or possible improvements and might even part with a small A reward to the rst nder of particular errors. This document is written in L TEX2e and stored in the le labelled ~twk/IIA/Codes.tex on emu in (I hope) read permitted form. My e-mail address is twk@dpmms. These notes are based on notes taken in the course of the previous lecturer Dr Pinch. Most of their virtues are his, most of their vices mine. Although the course makes use of one or two results from probability theory and a few more from algebra it is possible to follow the course successfully whilst taking these results on trust. There is a note on further reading at the end but 7] is a useful companion for the rst three quarters of the course (up to the end of section 8) and 9] for the remainder. Please note that vectors are row vectors unless otherwise stated.
Contents
1 2 3 4
What is an error correcting code? Hamming's breakthrough General considerations Linear codes
1
2 5 8 13
5 Some general constructions 6 Polynomials and elds 7 Cyclic codes 8 Shift registers 9 A short homily on cryptography 10 Stream cyphers 11 Asymmetric systems 12 Commutative public key systems 13 Trapdoors and signatures 14 Further reading 15 First Sheet of Exercises 16 Second Sheet of Exercises
18 22 27 33 37 39 46 48 52 54 57 60
are often `compressed', that is shortened by removing redundant structure2 In recognition of this fact we shall assume that we are asked to consider a collection of m messages each of which is equally likely. Our model is the following. When the `source' produces one of the m possible messages i say, it is fed into a `coder' which outputs a string ci of n binary digits. The string is then transmitted one digit at a time along a `communication channel'. Each digit has probability p of being mistransmitted (so that 0 becomes 1 or 1 becomes 0) independently of what happens to the other digits 0 p < 1=2]. The transmitted message is then passed through a `decoder' which either produces a message j (where we hope that j = i) or an error message and passes it on to the `receiver'. Exercise 1.1. Why do we not consider the case 1 p > 1=2? What if p = 1=2? An obvious example is the transmission of data from a distant space probe where (at least in the early days) the coder had to be simple and robust but the decoder could be as complex as the designer wished. On the other hand the decoder in a home CD player must be cheap but the encoding system which produces the disc can be very expensive. For most of the time we shall concentrate our attention on a code C f0 1gn consisting of the codewords ci. We say that C has size m = jC j. If m is large then we can carry a large number of possible messages (that
versible 'lossy compression' and reversible 'lossless compression'. For compact discs where bits are cheap the sound recorded can be reconstructed exactly. For digital sound broadcasting where bits are expensive the engineers make use of knowledge of the human auditory system (for example, the fact that we can not make out very soft noise in the presence of loud noises) to produce a result that might sound perfect (or nearly so) to us but which is in fact not. For mobile phones there can be greater loss of data because users do not demand anywhere close to perfection. For digital TV the situation is still more striking with reduction in data content from lm to TV of anything up to a factor of 60. However medical and satellite pictures must be transmitted with no loss of data. Notice that lossless coding can be judged by absolute criteria but the merits of lossy coding can only be judged subjectively. In theory lossless compression should lead to a signal indistinguishable (from a statistical point of view) from a random signal. In practice this is only possible in certain applications. As an indication of the kind of problem involved consider TV pictures. If we know that what is going to be transmitted is `head and shoulders' or `tennis matches' or `cartoons' it is possible to obtain extraordinary compression ratios by `tuning' the compression method to the expected pictures but then changes from what is expected can be disastrous. At present digital TV encoders merely expect the picture to consist of blocks which move at nearly constant velocity remaining more or less unchanged from frame to frame. In this as in other applications we know that after compression the signal still has non-trivial statistical properties but we do not know enough about them to exploit this.
2 In practice the situation is more complicated. Engineers distinguish between irre-
is we can carry more information) but as m increases it becomes harder to distinguish between di erent messages when errors occur. At one extreme, if m = 1, errors cause us no problems (since there is only one message) but no information is transmitted (since there is only one message). At the other extreme, if m = 2n, we can transmit lots of messages but any error moves us from one codeword to another. We are led to the following rather natural de nition. 2 De nition 1.2. The information rate of C is logn m . Note that, since m 2n the information rate is never greater than 1. Notice also that the values of the information rate when m = 1 and m = 2n agree with what we might expect. How should our decoder work? We have assumed that all messages are equally likely and that errors are independent (this would not be true if, for example, errors occured in bursts3 . Under these assumptions, a reasonable strategy for our decoder is to guess that the codeword sent is one which di ers in the fewest places from the string of n binary digits received. Here and elsewhere the discussion can be illuminated by the simple notion of a Hamming distance. De nition 1.3. If x y 2 f0 1gn we write
d(x y) =
n X j =1
jxj ; yj j
Lemma 1.5. We work with coding and transmission scheme described above. Let c 2 C and x 2 f0 1gn. (i) If d(c x) = r then Pr(x received given c sent) = pr (1 ; p)n;r : (ii) If d(c x) = r then Pr(c sent given x received) = A(x)pr (1 ; p)n;r where A(x) does not depend on r or c. (iii) If c0 2 C and d(c0 x) d(c x) then Pr(c sent given x received) Pr(c0 sent given x received) with equality if and only if d(c0 x) = d(c x).
The lemma just proved justi es our use, both explicit and implicit, throughout what follows of the so called maximum likelihood decoding rule. De nition 1.6. The maximum likelihood decoding rule states that a string x 2 f0 1gn received by a decoder should be decoded as (one of) the codewords at the smallest Hamming distance from x. Notice that, although this decoding rule is mathematically attractive, it may be impractical if C is large and there is no way of nding the codeword at the smallest distance from a particular x without making complete search through all the members of C .
2 Hamming's breakthrough
Although we have used simple probabilistic arguments to justify it, the maximum likelihood decoding rule will enable us to avoid probabilistic considerations for the rest of the course and to concentrate on algebraic and combinatorial considerations. The spirit of the course is exempli ed in the next two de nitions. De nition 2.1. We say that C is d error detecting if changing up to d digits in a codeword never produces another codeword. De nition 2.2. We say that C is e error correcting if knowing that a string of n binary digits di ers from some codeword of C in at most e places we can deduce the codeword. 5
Here are two simple schemes. Repetition coding of length n. We take codewords of the form c = (c c c : : : c) with c = 0 or c = 1. The code C is n ; 1 error detecting, and b(n ; 1)=2c error correcting. The maximum likelihood decoder chooses the symbol that occurs most often. (Here and elsewhere b c is the largest integer N and d e is the smallest integer M .) Unfortunately the information rate is 1=n which is rather low4. The paper tape code. Here and elsewhere it is convenient to give f0 1g the structure of the eld F 2 = Z2 by using arithmetic modulo 2. The codewords have the form c = (c1 c2 c3 : : : cn) with c1 , c2 , : : : , cn;1 freely chosen elements of F 2 and cn (the check digit) the element of F 2 which gives c1 + c2 + + cn;1 + cn = 0: The resulting code C is 1 error detecting since, if x 2 F n is obtained from 2 c 2 C by making a single error, we have x1 + x2 + + xn;1 + xn = 1: However it is not error correcting since, if x1 + x2 + + xn;1 + xn = 1 there are n codewords y with Hamming distance d(x y) = 1. The information rate is (n ; 1)=n. Traditional paper tape had 8 places per line each of which could have a punched hole or not so n = 8. Exercise 2.3. Machines tend to communicate in binary strings so this course concentrates on binary alphabets with two symbols. There is no particular di culty in extending our ideas to alphabets with n symbols though, of course, some tricks will only work for particular values of n. If you look at the inner title page of almost any recent book you will nd its International Standard Book Number (ISBN). The ISBN uses single digits selected from 0, 1, : : : , 8, 9 and X representing 10. Each ISBN consists of nine such digits a1 , a2, : : : , a9 followed by a single check digit a10 chosen so that 10a1 + 9a2 + + 2a9 + a10 0 mod 11: (*)
4 Compare the chorus `Oh no John, no John, no John no'.
(In more sophisticated language our code C consists of those elements a 2 F 10 11 P such that 10 (11 ; j )aj = 0.) j =1 (i) Find a couple of books5 and check that ( ) holds for their ISBNs6 . (ii) Show that ( ) will not work if you make a mistake in writing down one digit of an ISBN. (iii) Show that ( ) may fail to detect two errors. (iv) Show that ( ) will not work if you interchange two adjacent digits. Errors of type (ii) and (iv) are the most common in typing7 . In communication between publishers and booksellers both sides are anxious that errors should be detected but would prefer the other side to query errors rather than to guess what the error might have been.
Hamming had access to an early electronic computer but was low down in the priority list of users. He would submit his programs encoded on paper tape to run over the weekend but often he would have his tape returned on Monday because the machine had detected an error in the tape. `If the machine can detect an error' he asked himself `why can the machine not correct it?' and he came up with the following scheme. Hamming's original code. We work in F 7 . The codewords c are chosen to 2 satisfy the three conditions.
c1 + c3 + c5 + c7 = 0 c2 + c3 + c6 + c7 = 0 c4 + c5 + c6 + c7 = 0:
By inspection we may choose c3, c5, c6 and c7 freely and then c1, c2 and c4 are completely determined. The information rate is thus 4=7. Suppose that we receive the string x 2 F 7 . We form the syndrome 2 (z1 z2 z4) 2 F 3 given by 2
z1 = x1 + x3 + x5 + x7 z2 = x2 + x3 + x6 + x7 z4 = x4 + x5 + x6 + x7 :
If x is a codeword then (z1 z2 z4 ) = (0 0 0). If c is a codeword and the Hamming distance d(x c) = 1 then the place in which x di ers from c is given by z1 + 2z2 + 4z3 (using ordinary addition, not addition modulo 2) as
`snydrome' for `syndrome'.
5 In case of di culty your college library may be of assistance. 6 In fact, X is only used in the check digit place. 7 Thus the 1997{8 syllabus for this course contains the rather charming misprint of
may be easily checked using linearity and a case by case study of the seven binary sequences x containing one 1 and six 0s. The Hamming code is thus 1 error correcting. Exercise 2.4. Suppose we use eight hole tape with the standard paper tape code and the probability that an error occurs at a particular place on the tape (i.e. a hole occurs where it should not or fails to occur where it should) is 10;4. A program requires about 10 000 lines of tape (each line containing eight places) using the paper tape code. Using the Poisson approximation, direct calculation (possible with a hand calculator but really no advance on the Poisson method) or otherwise show that the probability that the tape will be accepted as error free by the decoder is less than .04%. Suppose now that we use the Hamming scheme (making no use of the last place in each line). Explain why the program requires about 17 500 lines of tape but that any particular line will be correctly decoded with probability about 1 ; (21 10;8) and the probability that the entire program will be correctly decoded is better than 99.6%. Hamming's scheme is easy to implement. It took a little time for his company to realise what he had done8 but they were soon trying to patent it. In retrospect the idea of an error correcting code seems obvious (Hamming's scheme had actually been used as the basis of a Victorian party trick) and indeed two or three other people discovered it independently, but Hamming and his Co-discoverers had done more than nd a clever answer to a question. They had asked an entirely new question and opened a new eld for mathematics and engineering. The times were propitious for the development of the new eld. Before 1940 error correcting codes would have been luxuries, solutions looking for problems, after 1950 with the rise of the computer and new communication technologies they became necessities. Mathematicians and engineers returning from wartime duties in code breaking, code making and general communications problems were primed to grasp and extend the ideas. The mathematical engineer Claude Shannon may be considered the presiding genius of the new eld.
3 General considerations
How good can error correcting and error detecting codes be? The following discussion is a natural development of the ideas we have already discussed.
believe it'.
8 Experienced engineers came away from working demonstrations muttering `I still don't
distance between distinct code words. We call a code of length n, size m and distance d a n m d] code. Less brie y, a set C F n , with jC j = m and 2 minfd(x y) : x y 2 C x 6= yg = d is called a n m d] code. By an n m] code we shall simply mean a code of length n and size m. Lemma 3.2. A code of minimum distance d can detect d ; 1 errors and correct b d;1 c errors. It cannot detect all sets of d errors and cannot correct 2 all sets of b d;1 c + 1 errors. 2 It is natural here and elsewhere to make use of the geometrical insight provided by the (closed) Hamming ball B (x r) = fy : d(x y) rg: Observe that jB (x r)j = jB (0 r)j for all x and so writing V (n r) = jB (0 r)j we know that V (n r) is the number of points in any Hamming ball of radius r. A simple counting argument shows that
r X n V (n r) = j : j =0
jC j V (2 e) : n
There is an obvious fascination (if not utility) in the search for codes which attain the exact Hamming bound. De nition 3.4. A code C of length n and size m which can correct e errors is called perfect if n m = V (2 e) : n 9
X = fx 2 F 90 : x1 = 1 x2 = 1 d(0 x) = 3g: 2
Show that corresponding to each x 2 X we can nd a unique c(x) 2 C such that d(c(x) x) = 2. (iv) Continuing with the argument of (iii) show that
d(c(x) 0) = 5
and that ci (x) = 1 whenever xi = 1. By looking at d(c(x) c(x0 )) for x x0 2 X and invoking the Dirichlet pigeon-hole principle, or otherwise, obtain a contradiction. (v) Conclude that there is no perfect 90 278 ] code.
We obtained the Hamming bound which places an upper bound on how good a code can be by a packing argument. A covering argument gives us the GSV (Gilbert, Shannon, Varshamov) bound in the opposite direction. Let us write A(n d) for the size of the largest code with minimum distance d. Theorem 3.7 (Gilbert, Shannon, Varshamov). We have n A(n d) V (n 2d ; 1) :
10
Until recently there were no general explicit constructions for codes which achieved the GVS bound (i.e. codes whose minimum distance d satis ed the inequality A(n d)V (n d ; 1) 2n). Such a construction was nally found by Garcia and Stricheuth by using `Goppa' codes. Engineers are, of course, interested in `best codes' of length n for reasonably small values of n but mathematicians are particularly interested in what happens as n ! 1. To see what we should look at recall the so called weak law of large numbers (a simple consequence of Chebychev's inequality). In our case it yields the following result. Lemma 3.8. Consider the model of a noisy transmission channel used in this course in which each digit had probability p of being wrongly transmitted independently of what happens to the other digits. If > 0 then Pr(number of errors in transmission for message of n digits (1 + )pn) ! 0 as n ! 1. By Lemma 3.2 a code of minimum distance d can correct b d;1 c errors. 2 Thus if we have an error rate p and > 0 we know that the probability that a code of length n with error correcting capacity d(1 + )pne code will fail to correct a transmitted message falls to zero as n ! 1. By de nition the biggest code with minimum distance d2(1 + )pne has size A(n d2(1 + )pne) and so has information rate log2 A(n d2(1+ )pne)=n. Study of the behaviour of log2 A(n n )=n will thus tell us how large an information rate is possible in the presence of a given error rate. De nition 3.9. If 0 < < 1=2 we write ( ( ) = lim sup log2 Ann n ) : n!1 De nition 3.10. We de ne the entropy function H : 0 1=2) ! R by H (0) = 0 and H ( ) = ; log2 ( ) ; (1 ; ) log2 (1 ; ) for all 0 < < 1=2 (Our function H is a very special case of a general measure of disorder.) Theorem 3.11. With the de nitions just given, 1 ; H ( ) ( ) 1 ; H ( =2) for all 0 < 1=2. 11
Using the Hamming bound (Theorem 3.3) and the GSV bound (Theorem 3.7) we see that Theorem 3.11 follows at once from the following result. Theorem 3.12. We have log2 V (n n ) ! H ( ) n as n ! 1. Our proof of Theorem 3.12 depends, as one might expect on a version of Stirling's formula. We only need the very simplest version proved in 1A. Lemma 3.13 (Stirling). We have loge n! = n loge n ; n + O(log2 n): We combine this with the remark that
V (n n ) =
X n
j n (m + 1) m
0 j n
where m = bn c. Although the GSV bound is very important a stronger result can be obtained for the error correcting power of the best long codes. Theorem 3.14 (Shannon's coding theorem). Suppose 0 < p < 1=2 and > 0. Then there exists an n0 (p ) such that for any n > n0 we can nd codes of length n which have the property that (under our standard model) the probability that a codeword is mistaken is less than and have information rate 1 ; H (p) ; . WARNING: Do not use this result until you have studied its proof. It is indeed a beautiful and powerful result but my statement conceals some traps for the unwary.] Thus in our standard setup, by using su ciently long code words, we can simultaneously obtain an information rate as close to 1 ; H (p) as we please and and an error rate as close to 0 as we please. Shannon's proof uses the kind of ideas developed in this section with an extra pinch of probability (he 12
chooses codewords at random ) but I shall not give it in the course. There is a nice simple treatment in Chapter 3 of 9]. In view of Hamming's bound it is not surprising that it can also be shown that we cannot drive the error rate down to close to zero and maintain an information rate 1 ; H0 > 1 ; H (p). To sum up, our standard set up, has capacity 1 ; H (p). We can communicate reliably at any xed information rate below this capacity but not at any rate above. However, Shannon's theorem which tells us that rates less than H (p) are possible is non-constructive and does not tell us how explicitly hoe to achieve these rates.
4 Linear codes
Just as R n is vector space over R and C n is vector space over C so F n is 2 vector space over the F 2 . (If you know about vector spaces over elds, so much the better, if not just follow the obvious paths.) A linear code is a subspace of F n . More formally we have the following de nition. 2 De nition 4.1. A linear code is a subset of F n such that 2 (i) 0 2 C , (ii) if x y 2 C then x + y 2 C . Note that if 2 F then = 0 or = 1 so that condition (i) of the de nition just given guarantees that x 2 C whenever x 2 C . We shall see that linear codes have many useful properties. Example 4.2. (i) The repetition code with
fC = fx : x = (x x : : : x)g
is a linear code. (ii) The paper tape code
C= x:
( X n
j =0
xj = 0
The veri cation is easy. In fact, examples (ii) and (iii) are `parity check codes' and so automatically linear as we shall see from the next lemma. 13
De nition 4.3. Consider a set P in F n . We say that C is the code de ned 2 by the set of parity checks P if the elements of C are precisely those x 2 F n 2
with
n X j =1
pj xj = 0
for all p 2 P .
We now prove the converse result. De nition 4.5. If C is a linear code we write C ? for the set of p 2 F n such that
n X j =1
pj xj = 0
dim C + dim C ? = n: Since the last part of P1 is not the most popular piece of mathematics in 1B we shall give an independent proof later (see the note after Lemma 4.13). Combining Lemma 4.6 (ii) with Lemma 4.7 we get the following corollaries. Lemma 4.8. If C is a linear code then (C ?)? = C . Lemma 4.9. Every linear code is de ned by parity checks. Our treatment of linear codes has been rather abstract. In order to put computational esh on the dry theoretical bones we introduce the notion of a generator matrix. 14
for all x 2 C . Thus C ? is the set of parity checks satis ed by C . Lemma 4.6. If C is a linear code then (i) C ? is a linear code, (ii) (C ?)? C . We call C ? the dual code to C . In the language of the last part of the course on linear mathematics (P1), ? is the annihilator of C . The following is a standard theorem of that C course. Lemma 4.7. If C is a linear code in F n then 2
Example 4.11. As examples we can nd generator matrices for the repetition code, the paper tape code and the original Hamming code.
Remember that the Hamming code is the code of length 7 given by the parity conditions
x1 + x3 + x5 + x7 = 0 x2 + x3 + x6 + x7 = 0 x4 + x5 + x6 + x7 = 0:
By using row operations and column permutations we can use Gaussian elimination we can give a constructive proof of the following lemma. Lemma 4.12. Any linear code of length n has (possibly after permuting the order of coordinates) a generator matrix of the form (Ir jB ): Notice that this means that any codeword x can be written as (yjz) = (yjyB ) where y = (y1 y2 : : : yr ) may be considered as the message and the vector z = yB of length n ; r may be considered the check digits. Any code whose codewords can be split up in this manner is called systematic. We now give a more computational treatment of parity checks. Lemma 4.13. If C is a linear code of length n with generator matrix G then a 2 C ? if and only if
GaT = 0T :
Thus
C ? = (ker G)T :
Thus using the rank, nullity theorem we get a second proof of Lemma 4.7. Lemma 4.13 also enables us to characterise C ?. 15
Lemma 4.14. If C is a linear code of length n and dimension r with generator the r n matrix G then if H is any n n ; r matrix with columns
forming a basis of ker G we know that H is a parity check matrix for C and its transpose H T is a generator for C ?.
Example 4.15. (i) The dual of the paper tape code is the repetition code.
(ii) Hamming's original code has dual with generator
01 @0
0 1 0 1 0 1 1 1 0 0 1 1A 0 0 0 1 1 1 1 (yjz) = (yjyB )
We saw above that the codewords of a linear code can be written where y may be considered as the vector of message digits and z = yB as the vector of check digits. Thus encoders for linear codes are easy to construct. What about decoders? Recall that every linear code of length n has a (non-unique) associated parity check matrix H with the property that x 2 C if and only if xH = 0. If z 2 F n we de ne the syndrome of z to be zH . The 2 following lemma is mathematically trivial but forms the basis of the method of syndrome decoding. Lemma 4.16. Let C be a linear code with parity check matrix H . If we are given z = x + e where x is a code word and the `error vector' e 2 F n , then 2
zH = eH:
Suppose we have tabulated the syndrome uH for all u with `few' non-zero entries (say, all u with d(u 0) K ). If our decoder receives z it computes the syndrome zH . If the syndrome is zero then z 2 C and the decoder assumes the transmitted message was z. If the syndrome of the received message is a non-zero vector w the decoder searches its list until it nds an e with eH = w. The decoder then assumes that the transmitted message was x = z ; e (note that z ; e will always be a codeword, even if not the right one). This procedure will fail if w does not appear in the list but for this to be case at least K + 1 errors must have occured. If we take K = 1, that is we only want a 1 error correcting code then writing e(i) for the vector in F n with 1 in the ith place and 0 elsewhere we 2 see that the syndrome e(i) H is the ith row of H . If the transmitted message z has syndrome zH equal to the ith row of H then the decoder assumes that 16
there has been an error in the ith place and nowhere else. (Recall the special case of Hamming's original code.) If K is large the task of searching the list of possible syndromes becomes onerous and, unless (as sometimes happens) we can nd another trick, we nd that `decoding becomes dear' although `encoding remains cheap'. We conclude this section by looking at weights and the weight enumeration polynomial for a linear code. The idea here is to exploit the fact that if C is linear code and a 2 C then a + C = C . Thus the `view of C ' from any codeword a is the same as the `view of C ' from the particular codeword 0. De nition 4.17. The weight w(x) of a vector x 2 F n is given by 2
Lemma 4.18. If w is the weight function on F n and x y 2 F n then 2 2 (i) w(x) 0, (ii) w(x) = 0 if and only if x = 0, (iii) w(x) + w(y) w(x + y).
Since the minimum (non-zero) weight in a linear code is the same as the minimum (non-zero) distance we can talk about linear codes of minimum weight d when we mean linear codes of minimum distance d. The pattern of distances in a linear code is encapsulated in the weight enumeration polynomial. De nition 4.19. Let C be a linear code of length n. We write Aj for the number of codewords of weight j and de ne the weight enumeration polynomial WC to be the polynomial in two real variables given by
WC (s t) =
n X j =0
Aj sj tn;j :
Here are some simple properties of WC . Lemma 4.20. Under the assumptions and with the notation of the De nition 4.19, the following results are true. (i) WC is a homogeneous polynomial of degree n. (ii) If C has rank r then WC (1 1) = 2r . (iii) WC (0 1) = 1. (iv) WC (1 0) takes the value 0 or 1. (v) WC (s t) = WC (t s) for all s and t if and only if WC (1 0) = 1. 17
(ii) If C is the paper tape code of length n, WC (s t) = 1 ((s + t)n +(t ; s)n ). 2
WC ? (s t) = 2; dim C WC (t ; s t + s):
We shall not give a proof and even the result may be considered as starred.
The fact that any two rows of H are linearly independent and a look at the appropriate syndromes gives us the main property of the general Hamming code. Lemma 5.4. The Hamming (n n ; d) code has minimum weight 3 and is a perfect 1 error correcting code n = 2d ; 1]. Hamming codes are ideal in situations where very long strings of binary digits must be transmitted but the chance of an error in any individual digit is very small. (Look at Exercise 2.4.) It may be worth remarking that, apart from the Hamming codes there are only a few (and, in particular, a nite number) of examples of perfect codes known. Here are a number of simple tricks for creating new codes from old. De nition 5.5. If C is a code of length n the parity check extension C + of C is the code of length n + 1 given by
n+1 X j =1
xj = 0 :
C ; and its shortening C 0 . How can we combine two linear codes C1 and C2? Our rst thought might be to look at their direct sum C1 C2 = f(xjy) : x 2 C1 y 2 C2g
but this is unlikely to be satisfactory. Lemma 5.9. If C1 and C2 are linear codes then we have the following relation between minimum distances.
De nition 5.6. If C is a code of length n the truncation C ; of C is the code of length n ; 1 given by C ; = f((x1 x2 : : : xn;1) : (x1 x2 : : : xn ) 2 C for some xn 2 F 2 g: De nition 5.7. If C is a code of length n the shortening (or puncturing) C 0 of C is the code of length n ; 1 given by C 0 = f((x1 x2 : : : xn;1 ) : (x1 x2 : : : xn;1 0) 2 C g: Lemma 5.8. If C is linear so is its parity check extension C +, its truncation
On the other hand if C1 and C2 satisfy rather particular conditions we can obtain a more promising construction. De nition 5.10. Suppose C1 and C2 are linear codes of length n with C1 C2 (i.e. with C2 a subspace of C1). We de ne the bar product C1 jC2 of C1 and C2 to be the code of length 2n given by
C1 jC2 = f(xjx + y) : x 2 C1 y 2 C2g: Lemma 5.11. Let C1 and C2 be linear codes of length n with C1 C2. Then the bar product C1 jC2 is a linear code with rank C1 jC2 = rank C1 + rank C2: The minimum distance of C1 jC2 satis es the inequality d(C1jC2) min(2d(C1) d(C2)): We now return to the construction of speci c codes. Recall that the Hamming codes are suitable for situations when the error rate p is very small and we want a high information rate. The Reed-Muller are suitable when the error rate is very high and we are prepared to sacri ce information rate. They were used by NASA for the radio transmissions from its planetary probes (a task which has been compared to signalling across the Atlantic with a child's torch9 ). We start by considering the 2d points P0, P1, : : : , P2d;1 of the space X = F d . Our code words will be of length n = 2d and will correspond to the 2 indicator functions IA on X . More speci cally the possible code word cA is given by cA = 1 if Pi 2 A i A=0 ci otherwise: for some A X . In addition to the usual vector space structure on F n we de ne a new 2 operation cA ^ cB = cA\B : Thus if x y 2 F n , 2 (x0 x1 : : : xn;1) ^ (y0 y1 : : : yn;1) = (x0 y0 x1y1 : : : xn;1yn;1):
that is the main thing.
9 Strictly speaking the comparison is meaningless. However, it sounds impressive and
20
= fp 2 X : pj = 0 1 j
d]g
hj = c j
together with the special vector
h0 = cX = (1 1 : : : 1): Exercise 5.12. Suppose that x y z 2 F n and A B X . 2 (i) Show that x ^ y = y ^ x. (ii) Show that (x + y) ^ z = x ^ z + y ^ z. (iii) Show that h0 ^ x = x. (iv) If cA + cB = cE nd E in terms of A and B . (v) If h0 + cA = cE nd E in terms of A. We refer to A0 = fh0 g as the set of terms of order zero. If Ak is the set of terms of order at most k then the set Ak+1 of terms of order at most k + 1
is de ned by
Ak+1 = fa ^ hj : a 2 Ak 1 j ng:
Less formally but more clearly the elements of order 1 are the hi, the elements of order 2 are the hi ^ hj with i < j , the elements of order 3 are the hi ^ hj ^ hk with i < j < k and so on. De nition 5.13. Using the notation established above, the Reed-Miller code RM (d r) is the linear code (i.e. subspace of F n ) generated by the terms of order r or less. Although the formal de nition of the Reed-Miller codes looks pretty impenetrable at rst sight, once we have looked at su ciently many examples it should become clear what is going on. Example 5.14. (i) The RM (3 0) code is the repetition code of length 8. (ii) The RM (3 1) code is the parity check extension of Hamming's original code. (iii) The RM (3 2) code is the paper tape code of length 8. (iii) The RM (3 3) code is the trivial code consisting of all the elements of F 3 . 2 21
We now prove the key properties of the Reed-Miller codes. We use the notation established above. Theorem 5.15. (i) The elements of order d or less (that is the collection of all possible wedge products formed from the hi ) span F n . 2 (ii) The elements of order d or less are linearly independent. (iii) The dimension of the Reed-Miller code RM (d r) is d + d + d + + d : r 0 1 2 (iv) Using the bar product notation we have RM (d r) = RM (d ; 1 r)jRM (d ; 1 r ; 1): (v) The minimum weight of RM (d r) is exactly 2d;r . Exercise 5.16. The Mariner mission to Mars used the RM (5 1) code. What was its information rate. What proportion of errors could it correct in a single code word? Exercise 5.17. Show that the RM (d d ; 2) code is the parity extension code of the Hamming (N N ; d) code with N = 2d ; 1.
22
aj X j
with coe cients in aj 2 K and its evaluation P (t) = n=0 aj tj for some j t 2 K . We manipulate polynomials in X according to the standard rules for polynomials but say that
n X j =0
aj X j = 0
if and only if aj = 0 for all j . Thus X 2 + X is a non-zero polynomial over F 2 all of whose values are zero. The following result is familiar, in essence, from school mathematics. Lemma 6.2 (Remainder theorem). (i) If P is a polynomial over a eld K and a 2 K then we can nd a polynomial Q and an r 2 K such that P (X ) = (X ; a)Q(X ) + r: (ii) If P is a polynomial over a eld K and a 2 K is such that P (a) = 0 then we can nd a polynomial Q such that P (X ) = (X ; a)Q(X ): The key to much of the elementary theory of polynomials lies in the fact that we can apply Euclid's algorithm to obtain results like the following. Theorem 6.3. Suppose that P is a set of polynomials,which contains at least one non-zero polynomial and has the following properties. (i) If Q is any polynomial and P 2 P then the product PQ 2 P . (ii) If P1 P2 2 P then P1 + P2 2 P . Then we can nd a non-zero P0 2 P which divides every P 2 P . Proof. Consider a non zero polynomial P0 of smallest degree in P . Recall that the polynomial P (X ) = X 2 + 1 has no roots in R (that is P (t) 6= 0 for all t 2 R ). However by considering the collection of formal expressions a + bi a b 2 R ] with the obvious formal de nitions of addition and multiplication and subject to the further condition i2 + 1 = 0 we obtain a eld C R in which P has a root (since P (i) = 0). We can perform a similar trick with other elds. 23
if we consider
!] = f0 1 ! 1 + !g
with obvious formal de nitions of addition and multiplication and subject to the further condition !2 + ! + 1 = 0 then F 2 ! ] is a eld containing F 2 in which P has root (since P (! ) = 0). Proof. The only thing we really need prove is that F 2 ! ] is a eld and to do that the only thing we need to prove is that F holds. Since
(1 + !)! = 1 this is easy. In order to state a correct generalisation of the ideas of the previous paragraph we need a preliminary de nition. De nition 6.5. If P is a polynomial over a eld K we say that P is reducible if there exists a non-constant polynomial Q of degree strictly less than P which divides P . If P is a non-constant polynomial which is not reducible then P is irreducible. Theorem 6.6. If P is an irreducible polynomial of degree n 2 over a eld K . then P has no roots in K . However if we consider
K !] =
(X n;1
j =0
aj !j : aj 2 K
with the obvious formal de nitions of addition and multiplication and subject to the further condition P (! ) = 0 then K ! ] is a eld containing K in which P has root. Proof. The only thing we really need prove is that K ! ] is a eld and to do that the only thing we need to prove is that F holds. Let Q be a non-zero polynomial of degree at most n ; 1. Since P is irreducible, the polynomials P and Q have no common factor of degree 1 or more. Hence, by Euclid's algorithm we can nd polynomials R and S such that
R(X )Q(X ) + S (X )P (X ) = 1
and so R(!)Q(!) + S (!)P (!) = 1. But P (!) = 0 so R(!)Q(!) = 1 and we have proved F. 24
K !] = K X ]=(P (X ))
where (P (X )) is the ideal generated by P (X ). This is a cleaner procedure which avoids the use of such phrases as `the obvious formal de nitions of addition and multiplication' but the underlying idea remains the same. Lemma 6.7. If P is polynomial over a eld K which does not factorise completely into linear factors then we can nd a eld L K in which P has more linear factors. Proof. Factor P into irreducible factors and choose a factor Q which is not linear. By Theorem 6.6 we can nd a eld L K in which Q has a root say and so by Lemma 6.2 a linear factor X ; . Since any linear factor of P in K remains a factor in the bigger eld L we are done. Theorem 6.8. If P is polynomial over a eld K then we can nd a eld L K in which P factorises completely into linear factors. We shall be interested in nite elds (that is elds K with only a nite number of elements). A glance at our method of proving Theorem 6.8 shows that the following result holds. Lemma 6.9. If P is polynomial over a nite eld K then we can nd a nite eld L K in which P factorises completely. In this context, we note yet another useful simple consequence of Euclid's algorithm. Lemma 6.10. Suppose that P is an irreducible polynomial over a eld K which has a linear factor X ; in some eld L K . If Q is a polynomial over K which has the factor X ; in L then P divides Q. We shall need a lemma on repeated roots. Lemma 6.11. Let K P eld. If P (X ) = Pn=0 aj X j is a polynomial over be j 0 (X ) = n;1 aj X j . K we de ne P j =1 (i) If P and Q are polynomials (P +Q)0 = P 0 +Q0 and (PQ)0 = P 0 Q+PQ0 . (ii) If P and Q are polynomials with P (X ) = (X ; a)2Q(X ) then
25
If L is a eld containing F 2 then 2y = (1+1)y = 0y = 0 for all y 2 L. We can thus deduce the following result which will be used in the next section. Lemma 6.12. If L is a eld containing F 2 and n is an odd integer then X n ; 1 can have no repeated linear factors as a polynomial over L. We also need a result on roots of unity given as part (v) of the next lemma. Lemma 6.13. (i) If G is a nite Abelian group and x y 2 G have coprime orders r and s then xy has order rs. (ii) If G is a nite Abelian group and x y 2 G have orders r and s then we can nd an element z of G with order the lowest common multiple of r and s. (iii) If G is a nite Abelian group then there exists an N and an h 2 G such that h has order N and gN = e for all g 2 G. (iv) If G is a nite subset of a eld K which is a group under multiplication then G is cyclic. (v) Suppose n is an odd integer. If L is a eld containing F 2 such that n ; 1 factorises completely into linear terms then we can nd an ! 2 L X such that the roots of X n ; 1 are 1, , 2, : : : n;1. (We call a primitive nth root of unity.) Proof. (ii) Consider z = xu y v where u is a divisor of r, v is a divisor of s, r=u and s=v are coprime and rs=(uv) = lcm(r s). (iii) Let h be an element of highest order in G and use (ii). (iv) By (iii) we can nd an integer N and a h 2 G such that h has order N and any element g 2 G satis es gN = 1. Thus X N ; 1 has a linear factor Q X ; g for each g 2 G and so g2G(X ; g) divides X N ; 1. It follows that the order jGj of G cannot exceed N . But by Lagrange's theorem N divides G. Thus jGj = N and g generates G. (v) Observe that G = f! : !n = 1g is an Abelian group with exactly n elements (since X n ; 1 has no repeated roots) and use (iv). Here is another interesting consequence of Lemma 6.13 (iv) Lemma 6.14. If K is a eld with 2n elements containing F 2 then there is an element k of K such that
K = f0g fkr : 0 r 2n ; 2
and k2n ;1 = 1. Proof. Observe that K n f0g forms a group under multiplication.
26
With this hint it is not hard to show that there is indeed a eld with 2n elements containing F 2 . Lemma 6.15. Let L be some eld containing F 2 in which X 2n;1 ; 1 = 0 factorises completely. Then K = fx 2 L : x2n = xg is a eld with 2n elements containing F 2 . Lemma 6.14 shows that that there is (up to eld isomorphism) only one eld with 2n elements containing F 2 . We call it F 2n . We call an element k with the properties given in Lemma 6.14 a primitive element of F 2n .
7 Cyclic codes
In this section we discuss a subclass of linear codes, the so called cyclic codes. De nition 7.1. A linear code C in F n is called cyclic if 2 (a0 a1 : : : an;2 an;1) 2 C ) (a1 a2 : : : an;1 a0) 2 C: Let us establish a correspondence between F n and the polynomials on F 2 2 modulo X n ; 1 by setting
Pa =
n X j =0
aj X j
whenever a 2 F 2 . (Of course, X n ; 1 = X n + 1 but in this context the rst expression seems more natural.) Exercise 7.2. With the notation just established show that (i) Pa + Pb = Pa+b, (ii) Pa = 0 if and only if a = 0. Lemma 7.3. A code C in F n is cyclic if and only if PC = fPa : a 2 C g 2 satis es the following two conditions (working modulo X n ; 1). (i) If f g 2 PC then f + g 2 PC . (ii) If f 2 PC and g is any polynomial then the product fg 2 PC . (In the language of abstract algebra, C is cyclic if and only if PC is an ideal of the quotient ring F 2 X ]=(X n ; 1).) From now on we shall talk of the code word f (X ) when we mean the code word a with Pa(X ) = f (X ). An application of Euclid's algorithm gives the following useful result. 27
Lemma 7.4. A code C of length n is cyclic if and only if (working modulo X n ; 1, and using the conventions established above) there exists a polynomial
g such that C = ff (X )g(X ) : f a polynomialg
(In the language of abstract algebra, F 2 X ] is a Euclidean domain and so a principal ideal domain. Thus the quotient F 2 X ]=(X n ; 1) is a principal ideal domain.) We call g(X ) a generator polynomial for C Lemma 7.5. A polynomial g is a generator for a cyclic code of length n if and only if it divides X n ; 1. Thus we must seek generators among the factors of X n ; 1 = X n + 1. If there are no conditions on n the result can be rather disappointing. Exercise 7.6. If we work with polynomials over F 2 then
X 2r + 1 = (X + 1)2r :
In order to avoid this problem and to be able to make use of Lemma 6.12 we shall take n odd from now on. (In this case the cyclic codes are said to be separable.) Notice that the task of nding irreducible factors (that is factors with no further factorisation) is a nite one. Lemma 7.7. Consider codes of length n Suppose that g(X )h(X ) = X n ; 1. Then g is a generator of a cyclic code C and h is a generator for a cyclic code which is the reverse of C ?. As an immediate corollary we have the following remark. Lemma 7.8. The dual of a cyclic code is itself cyclic. Lemma 7.9. If a cyclic code C of length n has generator g of degree n ; r then g (X ), Xg(X ), : : : , X r;1 g (X ) form a basis for C . Cyclic codes are thus easy to specify (we just need to write down the generator polynomial g) and to encode. Example 7.10. There are three cyclic codes of length 7 corresponding to irreducible polynomials of which two are versions of Hamming's original code. We know that X n + 1 factorises completely over some larger nite eld and, since n is odd, we know by Lemma 6.12 that it has no repeated factors. The same is therefore true for any polynomial dividing it. 28
De nition 7.12. A de ning set for a cyclic code C is a set A of elements in some eld K containing F 2 such that f 2 F 2 X ] belongs to C if and only if f ( ) = 0 for all 2 A. (Note that, if C has length n, A must be a set of zeros of X n ; 1.) Lemma 7.13. Suppose that A = f 1 2 : : : rg
is a de ning set for a cyclic code C in some eld K containing F 2 . Let B be the r n matrix over K whose j th column is
(1
2 j
:::
n;1 T j )
aB = 0
in K .
The columns in B are not parity checks in the usual sense since the code entries lie in F 2 and the computations take place in the larger eld K . With this background we can discuss a famous family of codes known as the BCH (Bose, Ray-Chaudhuri, Hocquenghem) codes. Recall that a primitive nth root of unity is an root of X n ; 1 = 0 such that every root is a power of De nition 7.14. Suppose that n is odd and K is a eld containing F 2 in which X n ; 1 factorises into linear factors. Suppose that 2 K is a primitive nth root of unity. A cyclic code C with de ning set
A=f
is a BCH code of design distance .
:::
;1 g
29
Note that the rank of C will be n ; k where k is the degree of the product those irreducible factors of X n ; 1 over F which have a zero in A. Notice also that k may be very much larger than . Example 7.15. (i) If K is a eld containing F 2 then (a + b)2 = a2 + b2 for all a b 2 K . (ii) If P 2 F 2 X ] and K is a eld containing F 2 then P (a)2 = P (a2 ) for all a 2 K . (iii) Let K be a eld containing F 2 in which X 7 ; 1 factorises into linear factors. If is a root of X 3 + X + 1 in K then is a primitive root of unity and 2 is also a root of X 3 + X + 1. (iv) We continue with the notation (iii). The BCH code with f 2g as de ning set is Hamming's original (7,4) code. The next theorem contains the key fact about BCH codes. Theorem 7.16. The minimum distance for a BCH code is at least as great as the design distance. Our proof of Theorem 7.16 relies on showing that the matrix B of Lemma 7.13 is non-singular for a BCH. To do this we use a result which every undergraduate knew in 1950. Lemma 7.17 (The van der Monde determinant). We work over a eld K . The determinant 1 1 1 ::: 1 x1 x2 x3 : : : xn Y x2 x2 x2 : : : x2 = (xi ; xj ) 1 2 3 n . . . ... . . . . . 1 j<i n . . . . xn;1 xn;1 xn;1 : : : xn;1 1 2 3 n How can we construct a decoder for a BCH code? From now on until the end of this section we shall suppose that we are using the BCH code C described in De nition 7.14. In particular C will have length n and de ning set A = f 2 : : : ;1g where is a primitive nth root of unity in K . Let t be the largest integer with 2t + 1 . We show how we can correct up to t errors. Suppose that a codeword c = (c0 c1 : : : cn;1) is transmitted and that the string received is r. We write e = r ; c and assume that E = f0 j n ; 1 : ej 6= 0g 30
has no more than t members. In other words e is the error vector and we assume that there are no more than t errors. We write
c(X ) = r (X ) = e(X ) =
n;1 X
X X
j =0 j =0 n;1
j =0 n;1
cj X j rj X j ej X j :
!(X ) =
Informally we write
n;1 X i=0
ei
j 2E j 6=i
(1 ; j X ):
!(X ) =
n;1 X
We take !(X ) = j !j X j and (X ) = j j X j . Note that ! has degree at most t ; 1 and degree at most t. Note that we know that 0 = 1 so both the polynomials ! and have t unknown coe cients. Lemma 7.19. If the error location polynomial is given the value of e and so of c can be obtained directly. We wish to make use of relations of the form 1 1 = X( j X )r : 1 ; j X r=0 Unfortunately it is not clear what meaning to assign to such a relation. One way round is to work modulo Z 2t (more formally, to work in K Z ]=(Z 2t )). We then have Z u 0 for all integers u 2t. 31
ei i 1 ;(Xi)X : i=0
m=0
( j Z )m
1:
m=0
( j Z )m:
X !(Z ) 2t;1 Z m e( m+1). (i) (Z ) m=0 (ii) e( m) = r( m) for all 1 m 2t. X !(Z ) 2t;1 Z mr( m+1 ). (iii) (Z ) m=0 P (iv) ! (Z ) X 2t;1 Z m r( m+1 ) (Z ): m=0 (v) !j = r( u+1) v for all 0 j 2t ; 1.
(vi) 0 =
u+v=j
u+v=j
r(
u+1 )
for all t j
2t ; 1.
Part (vi) of Lemma 7.21 completes our search for a decoding method, since determines E , E determines e and e determines c. It is worth noting that the system of equations in part (v) su ce to determine the pair and ! directly. Compact disk players use BCH codes. Of course errors are likely to occur in bursts (corresponding to scratches etc) and this is dealt with by distributing the bits (digits) in a single codeword over a much longer stretch of track. The code used can correct a burst of 4000 consecutive errors (2.5 mm of track). Unfortunately none of the codes we have considered work anywhere near the Shannon bound (see Theorem 3.14). We might suspect that this is because they are linear but Elias has shown that this is not the case. (We just state the result without proof.) Theorem 7.22. In Theorem 3.14 we can replace `code' by `linear code'. It is clear that much remains to be done. 32
Just as pure algebra has contributed greatly to the study of error correcting codes so the study of error correcting codes has contributed greatly to the study of pure algebra. The story of one such contribution is set out in T. M. Thompson's From Error-correcting Codes through Sphere Packings to Simple Groups 8] | a good, not too mathematical, account of the discovery of the last sporadic simple groups by Conway and others.
8 Shift registers
In this section we move towards cryptography but the topic discussed will turn out to have connections with the decoding of BCH codes as well. De nition 8.1. A general feedback shift register is a map f : F d ! F d 2 2 given by
+ a0xd;1
Exercise 8.4. Discuss brie y the e ect of omitting the condition ad;1 = 1
xn = a0 xn;d + a1 xn;d;1
+ ad;1 xn;1
over F 2 follows the 1A discussion of the same problem over R but is complicated by the fact that
n2 = n
33
C (X ) = X d ; a0X d;1 ; ; ad;2 X ; ad;1 : In the exercise below n is the appropriate polynomial in n. v
+ ad;1 xn;1
(*)
with aj 2 F 2 and a0 6= 0. (i) Suppose K is a eld containing F 2 such that the auxiliary polynomial C has a root in K . Then n is a solution of ( ) in K . (ii) Suppose K is a eld containing F 2 such that the auxiliary polynomial C has d distinct roots 1, 2, : : : , d in K . Then the general solution of ( ) in K is
xn =
d X j =1
bj
n j
for some bj 2 K . If x0 x1 : : : xd;1 2 F 2 then xn 2 F 2 for all n. (iii) Work out the rst few lines of Pascal's triangle modulo 2. Show that the functions fj : Z ! F 2
fj (n) = n j
are linearly independent in the sense that
m X j =0
aj fj (n) = 0
for all n implies aj = 0 for 1 j m. (iv) Suppose K is a eld containing F 2 such that the auxiliary polynomial C factorises completely into linear factors. If the root u has multiplicity mu 1 u q] then the general solution of ( ) in K is
xn =
bu v n v
n u
34
An strong link with the problem of BCH decoding is provided by Theorem 8.7 below. De nition 8.6. If we have a sequence (or stream) x0 , x1 , x2 , : : : of elements of F 2 then its generating function G is given by
G(Z ) =
1 X
n=0
xj Z j
Theorem 8.7. The stream (xn) comes from a linear feedback generator with
auxiliary polynomial C if and only if the generating function for the stream is (formally) of the form (Z ) G(Z ) = B(Z ) C with B a polynomial of degree strictly than that of C . If we can recover C from G then we have recovered the linear feedback generator from the stream. The link with BCH codes is established by looking at Lemma 7.21 (iii) and making the following remark. Lemma 8.8. If a stream (xn) comes from a linear feedback generator with auxiliary polynomial C of degree d then C is determined by the condition
G(Z )C (Z ) B (Z ) mod Z 2d with B a polynomial of degree at most d ; 1. We thus have the following problem. Problem Given a generating function G for a stream and knowing that (Z ) G(Z ) = B(Z ) C with B a polynomial of degree less than that of C and the constant term in C is c0 = 1, recover C .
The Berlekamp-Massey method In this method we do not assume that the degree d of C is known. The Berlekamp-Massey solution to this problem is based on the observation that, since
d X j =0
cj xn;j = 0
35
starting at Ar if it is known that r d. For each Aj we evaluate det Aj . If det Aj 6= 0 then j 6= d. If det Aj = 0 then j is a good candidate for d so we solve F on the assumption that d = j . (Note that a one dimensional subspace of F d+1 contains only one non-zero vector.) We then check our candidate for (c0 c1 : : : cd) over as many terms of the stream as we wish. If it fails the test we then know that d j and we start again. As we have stated it, the Berlekamp-Massey method is not an algorithm in the strict sense of the term although it becomes one if we put an upper bound on the possible values of d. (A little thought shows that if no upper bound is put on d, no algorithm is possible because, with a suitable initial stream a linear feedback register with large d can be made to produce a stream whose initial values would be produced by a linear feedback register with much smaller d. For the same reason the Berlekamp-Massey will produce the B of smallest degree which gives G and not necessarily the original B .) In practice, however, the Berlekamp-Massey method is very e ective in cases when d is unknown. It might be thought that evaluating determinants is hard but we can use row reduction to triangularise the matrices and use the fact that Ak;1 is a sub-matrix of Ak to reduce the work still further.
A method based on Euclid's algorithm (This is starred and will be omitted if time is short.) For this method we need to knowP degree d of C . P1 x Z j we take A(Z ) = the;1 x Z j so that 2d Writing G(Z ) = j=0 j j =0 j B (Z ) = A(Z ) + Z 2dU (Z ) C (Z ) for some power series U . It follows that B (Z ) = A(Z )C (Z ) + Z 2dW (Z ) (y)
(with c0 = 1) for all n d we have 0 10 1 0 1 xd xd;1 : : : x1 x0 1 0 Bxd+1 xd : : : x2 x1C Bc1C B0C B . . . . . C B . C = B.C F B .. .. . . .. .. C B .. C B .. C @ A@ A @ A x2d x2d;1 : : : xd+1 xd cd 0 The Berlekamp-Massey method tells us to look successively at the matrices 0x x x 1 2 1 0 A1 = (x0 ) A2 = x1 x0 A3 = @x3 x2 x1 A : : : x2 x1 x x x
4 3 2
36
where A(Z ) is known but B (Z ), C (Z ) and the power series W (Z ) are unknown. We now apply Euclid's algorithm to R0(Z ) = Z 2d , R1(Z ) = A(Z ) obtaining, as usual,
R0 (Z ) = R1 (Z )Q1(Z ) + R2 (Z ) R1 (Z ) = R2 (Z )Q2(Z ) + R3 (Z ) R2 (Z ) = R3 (Z )Q3(Z ) + R4 (Z ) and so on, but instead of allowing the algorithm to run its full course we stop at the rst point when the degree of Rj is no greater than d. Call ~ the polynomial Rj so obtained B . By the method associated with Bezout's ~ ~ theorem we can nd polynomials C and W such that ~ ~ Rj (Z ) = R1(Z )C (Z ) + R0 (Z )W (Z )
and so ~ ~ ~ B (Z )A(Z )C (Z ) + Z 2dW (Z ):
yy
~ ~ (i) B and C both have degree d or less. ~ B (Z ) and B (Z ) agree up to the term (ii) The power series expansions of ~ C (Z ) C (Z ) 2d . Z ~ ~ BC ; B C van(iii) The rst 2d terms of the power series expansions of ~ CC ish. ~ ~ BC ; B C is the generating sequence for a linear (iv) The power series of ~ CC ~ feedback system with auxiliary (or feedback) polynomial C C . ~ ~ (v) We have B = B and C = C . This method is called the Skorobogarov decoder.
discovered'. The new mathematical science of cryptography with its promise of codes which are `provably hard to break' seems to make everything that has gone before irrelevant. It should, however, be observed that the best cryptographic systems of our ancestors (such as diplomatic `book codes') served their purpose of ensuring secrecy for a relatively small number of messages between a relatively small number of people extremely well. It is the modern requirement for secrecy on an industrial scale to cover endless streams of messages between many centres which has made necessary the modern science of cryptography. More pertinently it should be remembered that the German Submarine Enigma codes not only appeared to be `provably hard to break' (though not against the modern criteria of what this should mean) but, considered in isolation probably were unbreakable in practice11 . Fortunately the Submarine codes formed part of an `Enigma system' with certain exploitable weaknesses. (For an account of how these weaknesses arose and how they were exploited see Kahn's Seizing the Enigma 3].) Even the best codes are like the lock on a safe. However good the lock is, the safe may be broken open by brute force, or stolen together with its comments, or a key holder may be persuaded by fraud or force to open the lock, or the presumed contents of the safe may have been tampered with before they go into the safe, or : : : . The coding schemes we shall consider, are at best, cryptographic elements of larger possible cryptographic systems. The planning of cryptographic systems requires not only mathematics but engineering, economics, psychology, humility and an ability to learn from past mistakes. Those who do not learn the lessons of history are condemned to repeat them. In considering a cryptographic system is important to consider its purpose. Consider a message M sent by A to B . Possible aims include Secrecy A and B can be sure that no third party X can read the message M. Integrity A and B can be sure that no third party X can alter the message M. Authenticity B can be sure that A sent the message M . Non-repudiation B can prove to a third party that A sent the message M . When you ll out a cheque giving the sum both in numbers and words you are seeking to protect the integrity of the cheque. When you sign a traveller's cheque `in the presence of the paying o cer' the process is intended, from your point of view to protect authenticity and, from the bank's point of view to produce non-repudiation.
11 Some versions remained unbroken until the end of the war.
38
Another point to consider is the level of security aimed at. It hardly matters if a few people use forged tickets to travel on the underground, it does matter if a single unauthorised individual can gain privileged access to a bank's central computer system. If secrecy is aimed at, how long must the secret be kept? Some military and nancial secrets need only remain secret for a few hours, others must remain secret for years. We must also, to conclude this non-exhaustive list, consider the level of security required. Here are three possible levels. (1) Prospective opponents should nd it hard to compromise your system even if they are in possession of a plentiful supply of encoded messages Ci. (2) Prospective opponents should nd it hard to compromise your system even if they are in possession of a plentiful supply of pairs (Mi Ci) of messages Mi together with their encodings Ci. (3) Prospective opponents should nd it hard to compromise your system even if they are allowed to produce messages Mi and given their encodings Ci. Clearly safety at level (3) implies safety at level (2) and safety at level (2) implies safety at level (1). Roughly speaking, the best Enigma codes satis ed (1). The German Navy believed on good but mistaken grounds that they satis ed (2). Level (3) would have appeared evidently impossible to attain until a few years ago. Nowadays, level (3) is considered a minimal requirement for a really secure system.
10 Stream cyphers
One natural way of enciphering is to use a stream cypher. We work with streams (that is, sequences) of elements of F 2 . We use cypher stream k0, k1, k2 : : : . The plain text stream p0, p1, p2 , : : : is enciphered as the cypher text stream z0 , z1 , z2 , : : : given by zn = pn + kn: This is an example of a private key or symmetric system. The security of the system depends on a secret (in our case the cypher stream) k shared between the cypherer and the encipherer. Knowledge of an enciphering method makes it easy to work out a deciphering method and vice versa. In our case a deciphering method is given by the observation that pn = zn + kn: (Indeed, writing (p) = p + z we see that the enciphering function has the property that 2 = the identity map. Cyphers like this are called symmetric.) 39
In the one-time pad rst discussed by Vernam in 1926 the cypher stream is a random sequence kj = Kj where the Kj are independent random variables with Pr(Kj = 0) = Pr(Kj = 1) = 1=2: If we write Zj = pj + Kj then we see that the Pj are independent random variables with Pr(Pj = 0) = Pr(Pj = 1) = 1=2: Thus (in the absence of any knowledge of the ciphering stream) the codebreaker is just faced by a stream of perfectly random binary digits. Decipherment is impossible in principle. It is sometimes said that it is hard to nd random sequences, and it is indeed rather harder than might appear at rst sight, but it is not too di cult to rig up a system for producing `su ciently random' sequences12 . The secret services of the former Soviet Union were particularly fond of one-time pads. The real di culty lies in the necessity for sharing the secret sequence k. If a random sequence is reused it ceases to be random (it becomes `the same code as last Wednesday' or the `the same code as Paris uses') so, when there is a great deal of code tra c, new one-time pads must be sent out. If random bits can be safely communicated so can ordinary messages and the exercise becomes pointless. In practice we would like to start from a short shared secret `seed' and generate a ciphering string k that `behaves like a random sequence'. This leads us straight into deep philosophical waters13 . As might be expected there is an illuminating discussion in Chapter III of Knuth's marvellous The Art of Computing Programming 6]. Note in particular his warning: : : : random numbers should not be generated with a method chosen at random. Some theory should be used. One way that we might try to generate our ciphering string is to use a general feedback shift register f of length d with the initial ll (k0 k1 : : : kd;1) as the secret seed. Take ten books, convert to P12=1 x 1000+of+ yours favouriteslong the output of yourbinary sequences x and set k = 10 + where is favourite `pseudo-random number generator'. Give a disc with a copy of k to your friend and, provided both of you obey
j n n j j j n n n
some elementary rules, your correspondence will be safe from MI5. The anguished debate in the US about codes and privacy refers to the privacy of large organisations and their clients, not the privacy of communication from individual to individual. 13 Where we drown at once, since, the best (at least my opinion) modern view is that any sequence that can be generated by a program of reasonable length from a `seed' of reasonable size is automatically non-random.
40
(i) f (x0 x1 : : : xd;1 ) = (x0 x1 : : : xd;1 ) if and only if (x0 x1 : : : xd;1 ) = (0 0 : : : 0). (ii) Given any initial ll (k0 k1 : : : kd;1 ) there will exist N M 2d ; 1 such that the output stream k satis es kr+N = kr for all r M .
We can complement Lemma 10.2 by using Lemma 6.15 and the associated the discussion. Lemma 10.3. A linear feedback register of length d attains its maximal period 2d ; 1 (for a non-trivial initiald ll) when the roots of the feedback polynomial are primitive elements of F 2 . (We will note why this result is plausible but we will not prove it.) It is well known that short period streams are dangerous. During World War II the British Navy used codes whose period was adequately long for peace time use. The massive increase in tra c required by war time conditions meant that the period was now too short. By dint of immense toil German naval code breakers were able to identify coincidences and by this means slowly break the British codes. Unfortunately, whilst short periods are de nitely unsafe it does not follow that long periods guarantee safety. Using the Berlekamp-Massey method we see that stream codes based on linear feedback registers are unsafe at level (2). Lemma 10.4. Suppose that an unknown cypher stream k0, k1, k2 : : : is produced by an unknown linear feedback register f of unknown length d D. The plain text stream p0 , p1 , p2 , : : : is enciphered as the cypher text stream z0 , z1 , z2 , : : : given by
zn = pn + kn:
If we are given p0 , p1 , : : : p2D;1 and z0 , z1 , : : : z2D;1 then we can nd kr for all r.
Thus if we have a message of length twice the length of the linear feedback register together with its encipherment the code is broken. It is easy to construct immensely complicated looking linear feedback registers with hundreds of registers. Lemma 10.4 shows that, from the point 41
of view of a determined, well equipped and technically competent opponent, cryptographic systems based on such registers are the equivalent of leaving your house key hidden under the door mat. Professionals say that such systems seek `security by obscurity'. However, if you do not wish to ba e the CIA, but merely prevent little old ladies in tennis shoes watching subscription television without paying for it, systems based on linear feedback registers are cheap and quite e ective. Whatever they may say in public, large companies are happy to tolerate a certain level of fraud. So long as 99.9% of the calls made are paid for, the pro ts of a telephone company are essentially una ected by the .1% which `break the system'. What happens if we try some simple tricks to increase the complexity of the cypher text stream. Lemma 10.5. If xn is a stream produced by a linear feedback system of length N with auxiliary polynomial P and yn is a stream produced by a linear feedback system of length N with auxiliary polynomial Q then xn + yn is a stream produced by a linear feedback system of length N + M with auxiliary polynomial P (X )Q(X ). Note that this means that adding streams from two linear feedback system is no more economical than producing the same e ect with one. Indeed the situation may be worse since a stream produced by linear feedback system of given length may, possibly, also be produced by another linear feedback system of shorter length. Lemma 10.6. Suppose that xn is a stream produced by a linear feedback system of length N with auxiliary polynomial P and yn is a stream produced by a linear feedback system of length N with auxiliary polynomial Q. Let P have roots 1 , 2, : : : N and Q have roots 1 , 2, : : : M over some eld K F 2 . Then xnyn is a stream produced by a linear feedback system of length NM with auxiliary polynomial
Y Y
1 i N1 i M
(X ;
i j ):
We shall probably only prove Lemmas 10.5 and 10.6 in the case when all roots are distinct, leaving the more general case as an easy exercise. We Q Q shall also not prove that the polynomial 1 i N 1 i M (X ; i j ) obtained in Lemma 10.6 actually lies in F 2 but (for those who are familiar with the phrase in quotes) this is an easy exercise in `symmetric functions of roots'. Here is an even easier remark. 42
and yn is a stream which is periodic with period M . Then the streams xn + yn and xn yn are periodic with periods dividing the lowest common multiple of N and M . Exercise 10.8. One of the most con dential German codes (called FISH by the British) involved a complex mechanism which the British found could be simulated by two loops of paper tape of length 1501 and 1497. If kn = xn + yn where xn is a stream of period 1501 and yn is stream of period 1497 what is the longest possible period of kn . How many consecutive values of kn do you need to to specify the sequence completely. It might be thought that the lengthening of the underlying linear feedback system obtained in Lemma 10.6 is worth having but it is bought at a substantial price. Let me illustrate this by an informal argument. Suppose we have 10 streams xj n (without any peculiar properties) produced linear Q feedback registers of length about 100. If we form kn = 10 xj n then the j =1 Berlekamp-Massey method requires of the order of 1020 consecutive values of kn and the periodicity of kn can be made still more astronomical. Our cypher key stream kn appears safe from prying eyes. However it is doubtful if the prying eyes will mind. Observe that (under reasonable conditions) about 2;1 Q of the xj n will have the value 1 and about 2;10 of the kn = 10 xj n will j =1 have value 1. Thus if zn = pn + kn, in more than 999 cases out of a 1000 we will have zn = pn. Even if we just combine two streams xn and yn in the way suggested we may expect xn yn = 0 for about 75% of the time. Here is another example where the apparent complexity of the cypher key stream is substantially greater than its true complexity. Example 10.9. The following is a simpli ed version of a standard satellite TV decoder. We have 3 streams xn , yn, zn produced by linear feedback registers. If the cypher key stream is de ned by
kn =xn kn =yn
then
if zn = 0 if zn = 1
kn = (yn + xn )zn + xn
and the cypher key stream is that produced by linear feedback register. It might be thought that the best way round these di culties is to use a non-linear feedback generator f . This is not the easy way out that it appears.
43
If chosen by an amateur the complicated looking f so produced will have the apparent advantage that we do not know what is wrong with it and the very real disadvantage that we do not know what is wrong with it. Another approach is to observe that, so far as the potential code breaker is concerned, the cypher stream method only combines the `unknown secret' (here the feedback generator f together with the seed (k0 k1 : : : kd;1)) with the unknown message p in a rather simple way. It might be better to consider a system with two functions F : F m F n ! F q and G : F m F q ! F n . such 2 2 2 2 2 2 that G(k F (k p)) = p: Here k will be the shared secret, p the message z = F (k p) the encoded message we can be decoded by using the fact that G(k z) = p. In the next section we shall see that an even better arrangement is possible. However, arrangements like this have the disadvantage that the the message p must be entirely known before it is transmitted and the encoded message z must have been entirely received before in can be decoded. Stream ciphers have the advantage that they can be decoded `on the y'. They are also much more error tolerant. A mistake in the coding, transmission or decoding of a single element only produces an error in a single place of the sequence. There will continue to be circumstances where stream ciphers are appropriate. There is one further remark to be made. Suppose that, as is often the case, that we know F , that n = q and we know the `encoded message' z. Suppose also that we know that the `unknown secret' or `key' k 2 K F m and the 2 `unknown message' p 2 P F n . We are then faced with the problem:- Solve 2 the system z = F (k p) where k 2 K p 2 P : F Speaking roughly, the task is hopeless unless F has a unique solution14. Speaking even more roughly, this is unlikely to happen if jKjjPj > 2n and is likely to happen if 2n is substantially greater than jKjjPj. (Here, as usual, jBj denotes the number of elements of B.)
At the moment of its creation, it appeared as a series of letters not yet joined up in the form of words. For this reason, in the Torah rolls there appear neither vowels nor punctuation, nor accents for the original Torah was nothing but a disordered heap of letters. Furthermore, had it not been for Adam's sin, these letters might have been joined di erently to form another story. For the kabalist, God will abolish the present ordering of the letters, or else will teach us how to read them according to a new disposition only after the coming of the Messiah.' ( 1], Chapter 2.)
14 `According to some, the primordial Torah was inscribed in black ames on white re.
44
Now recall the de nition of the information rate given in De nition 1.2. If the message set M has information rate and the key set (that is the shared secret set) K has information rate then, taking logarithms we see that if n;m ;n is substantially greater than 0 then F is likely to have a unique solution, but if it is substantially smaller this is unlikely. Example 10.10. If instead of using binary code we consider an alphabet of 27 letters (the English alphabet plus a space) we must take logarithms to the base 27 but the considerations above continue to apply. The English language treated in this way has information rate about .4. (This is very much a ball park gure. The information rate is certainly less than .5 and almost certainly greater than .2.) (i) In the Caesar code we replace the ith element of our alphabet by the i + j th (modulo 27). The shared secret is a single letter (the code for A say). We have m = 1, = 1 and :4. n ; m ; n :6n ; 1: If n = 1 (so n ; m ; n ;:4) it is obviously impossible to decode the message. If n = 10 (so n ; m ; n 5) a simple search through the 27 possibilities will almost always give a single possible decode. (ii) A simple substitution code a permutation of the alphabet is chosen and applied to each letter of the code in turn. The shared secret is a sequence of 26 letters (giving the coding of the rst 26 letters, the 27th can then be deduced). We have m = 26, = 1 and :4. n ; m ; n :6n ; 26: In the Dancing Men Sherlock Holmes solves such a code with n = 68 (so n;m ;n 15) without straining the reader's credulity too much and would think that, unless the message is very carefully chosen most of my audience could solve such a code with n = 200 (so n ; m ; n 100). (iii) In the one-time pad m = n and = 1 so (if > 0) n ; m ; n = ;n ! ;1 as n ! 1. (iv) Note that the larger is the slower n ; m ; n increases. This corresponds to the very general statement that the higher the information rate of the messages the harder it is to break the code in which they are sent. 45
The ideas just introduced can be formalised by the notion of unicity distance. De nition 10.11. The unicity distance of a code is the number of bits of message required to exceed the number of bits of information in the key plus the number of bits of information in the message. If the reader complains that there is a faint smell of red herring about this de nition, I would be inclined to agree. Without a clearer discussion of `information content' than is given in this course it must remain more of a slogan than a de nition. If we only use our code once to send a message which is substantially shorter than the unicity distance we can be con dent that no code breaker, however gifted, could break it, simply because there is there is no unambiguous decode. (A one-time pad has unicity distance in nity.) However, the fact that there is a unique solution to a problem does not mean that it is easy to nd. We have excellent reasons, some of which are spelled out in the next section, to believe that there exist codes for which the unicity distance is essentially irrelevant to the maximum safe length of a message.
11 Asymmetric systems
Towards the end of the previous section we discussed a general coding scheme depending on a shared secret key k known to the encoder and the decoder. However, the scheme can be generalised still further by splitting the secret in two. Consider a system with two functions F : F m F n ! F q and 2 2 2 G : F m F p ! F n . such that 2 2 2
G(l F (k p)) = p:
Here (k l) will be be a pair of secrets, p the message z = F (k p) the encoded message which can be decoded by using the fact that G(l z) = p. In this scheme the encoder must know k but need not know l and the decoder must know l and but need not know k. Such a system is called assymetric. So far the idea is interesting but not exciting. Suppose however, that we can show that (i) knowing F , G and l it is very hard to nd k, (ii) if we do not know k then, even if we know F and G, it very hard to nd p F (k p). Then the code is secure at what we called level (3). 46
Lemma 11.1. Suppose that the conditions speci ed above hold. Then an opponent who is entitled to demand the encodings zi of any messages pi they choose to specify will still nd it very hard to nd p when given F (k p). ; Let us write F (k p) = pKA and G(l; z) = zKA and think of pKA as participant A's encipherment of p and zKA as participant B 's decipherment of z. We then have ; (pKA )KA = p:
1 1 1
Lemma 11.1 tells us that such a system is secure however many messages are sent. Moreover, if we think of A a a spy-master he can broadcast KA to the world (that is why such systems are called public key systems) and invite anybody who wants to spy for him to send him secret messages in total con dence. It is all very well to describe such a code but do they exist? There is very strong evidence that they do but so far all mathematicians have been able to do is to show that provided certain mathematical problems which are believed to be hard are indeed hard then good codes exist. The following problem is believed to be hard. Problem Given an integer N which is known to be the product N = pq of two primes p and q, nd p and q. Several schemes have been proposed based on assumption that this factorisation is hard. (Note however that it is easy to nd large primes p and q.) We give a very elegant scheme due to Rabin and Williams. It makes use of some simple number theoretic results from 1A and 1B. The following result was proved towards the end of the course Quadratic Mathematics and is, in any case, easy to obtain by considering primitive roots. Lemma 11.2. If p is an odd prime the congruence
x2 d mod p is soluble if and only if d 0 or d(p;1)=2 1 modulo p. Lemma 11.3. Suppose p is a prime such that p = 4k ; 1 for some integer k. Then if the congruence x2 d mod p has any solution, it has dk as a solution. We now call on the Chinese remainder theorem.
47
Lemma 11.4. Let p and q be primes of the form 4k ; 1 and set N = pq.
Then the following two problems are of equivalent di culty. (A) Given N and d nd all the m satisfying
m2 d mod N:
(B) Given N nd p and q.
(Note that, provided that that d 6 0, knowing the solution to (A) for any d gives us the four solutions for d = 1.) The result is also true but much harder to prove for general primes p and q. At the risk of giving aid and comfort to followers of the Lakatosian heresy it must be admitted that the statement of Lemma 11.4 does not really tell us what the result we are proving is, although the proof makes it clear that the result (whatever it may be) is certainly true. However, with more work, everything can be made precise. We can now give the Rabin-Williams scheme. The spy-master A selects two very large primes p and q. (Since he has only done an undergraduate course in mathematics he will take p and q of the form 4k ; 1.) He keeps the pair (p q) secret but broadcasts the public key N = pq. If B wants to send him a message she writes it in binary code splits it into blocks of length m with 2m < N < 2m+1 . Each of these blocks is a number rj with 0 rj < N . B computes sj such that rj2 sj modulo N and sends sj . The spy-master (who knows p and q) can use the method of Lemma 11.4 to nd one of four possible values for rj (the four square roots of sj ). Of these four possible message blocks it is almost certain that three will be garbage so the fourth will be the desired message. If the reader re ects, she will see that the ambiguity of the root is genuinely unproblematic. (If the decoding is mechanical then making each block start with some xed sequence of length 50 will reduce the risk of ambiguity to negligible proportions.) Slightly more problematic, from the practical point of view, is the possibility that some one could be known to have sent a very short message, that is to have started with an m such that 1 m N 1=2 but provided sensible precautions are taken this should not occur.
and satisfying the condition that knowledge of KA did not help very much in ; nding KA 1 . We usually require, in addition, that our system be commutative in the sense that ;1 (pKA )KA = p:
; and that knowledge of KA 1 does not help very much in nding KA. The Rabin{Williams scheme, as described in the last section, does not have this property. Commutative public key codes are very exible and provide us with simple means for maintaining integrity, authenticity and non-repudiation. (This is not to say that non-commutative codes can not do the same simply that commutativity makes many things easier.) ; ; KA and KA 1. Then A can broadcast KA 1 to everybody so that everybody ; can decode but only A can encode. (We say that KA 1 is the public key and KA the private key.) Then, for example, example, A could issue tickets to the castle ball carrying the coded message `admit Joe Bloggs' which could be read by the recipients and the guards but would be unforgeable. However, for the same reason, A could not deny that he had issued the invitation.
Authenticity If B wants to be sure that A is sending a message then B can send A a harmless random message q. If B receives back a message p such ; that pKA ends with the message q then A must have sent it to B . (Any
1
body can copy a coded message but only A can control the content.)
1 1 1
; Signature Suppose now that B owns a commutative code pair (KB KB 1) ; and has broadcast KB 1.;If A wants to send a message p to B he computes ; ; q = pKA and sends pKB followed by (qKA )KB . B can now use the fact
that
(qKB )KB = q
; to recover p and q. B then observes that qKA 1 = p. Since only A can produce a pair (p q) with this property, A must have written it.
;1
There is now a charming little branch of the mathematical literature based on these ideas in which Albert gets Bertha to authenticate a message from Caroline to David using information from Eveline and Fitzpatrick, Gilbert and Harriet play coin tossing down the phone and Ingred, Jacob, Katherine and Laszlo play bridge without using a pack of cards. However a 49
cryptographic system is only as strong as its weakest link. Unbreakable password systems do not prevent computer systems being regularly penetrated by `hackers' and however `secure' a transaction on the net may be it may still involve a rogue on one end and a fool on the other. The most famous candidate for a commutative public key system is the RSA (Rivest, Shamir, Adleman) system. It was the RSA system the rst convinced the mathematical community that public key systems might be feasible. The reader will have met the RSA in 1A but we will push the ideas a little bit further. Lemma 12.1. Let p and q be primes. If N = pq and (N ) = lcm(p;1 q;1) then M (N ) 1 (mod N ) for all integers M . Since we wish to appeal to Lemma 11.4 we shall assume in what follows that we have secretly chosen large primes p and q of the form 4k ; 1. (However, as before, the arguments can be made to work for general large primes p and q.) We choose an integer e and then use Euclid's algorithm to nd an integer d such that de 1: (mod (N )) Since others may be better psychologists than we are, we would be wise to use some sort of random method for choosing p, q and e. The public key includes the value of d and N but we keep secret the value of e. Given a number M with 1 M N ; 1 we encode it as the integer E with 1 M N ; 1 E M d (mod N ): The public decoding method is given by the observation that E e M de M: As was observed in 1A, high powers are easy to compute. To show that (providing that factoring N is indeed hard) nding d from e and N is hard we use the following lemma. Lemma 12.2. Suppose that d, e and N are as above. Set de ; 1 = 2ab where b is odd. (i) a 1. (ii) If y xb (mod N ) then there exists an r with 1 r 2a;1 such that yr 6 1 but yr 1 (mod N ): 50
Combined with Lemma 11.4, the idea of Lemma 12.2 gives a fast probabilistic algorithm where by making random choices of x we very rapidly reduce the probability that we can not nd p and q to as close to zero as we wish. Lemma 12.3. The problem of nding d from the public information e and N is, essentially as hard as factorising N . Remark 1 At rst glance we seem to have done as well for the RSA code as for the Rabin{Williams code. But this is not so. In Lemma 11.4 we showed that nding the four solutions of M 2 E (mod N ) was equivalent to factorising N . In the absence of further information, nding one root is as hard as nding another. Thus the ability to break the Rabin-Williams code (without some tremendous stroke of luck) is equivalent to the ability to factor N . On the other hand it is a priori, possible that it might be possible to nd a decoding method for the RSA code which did not involve knowing d. Thus it might be possible to break the RSA code without nding d. It must, however, be said that, in spite of this problem, the RSA code is much used in practice and the Rabin{Williams code is not. Remark 2 It is natural to ask what evidence there is that the factorisation problem really is hard. Properly organised, trial division requires O(N 1=2 ) operations to factorise a number N . This order of magnitude was not bettered until 1972 when Lehman produced a O(N 1=3 ) method. In 1974, Pollard15 produced a O(N 1=4 ) method. In 1979, as interest in the problem grew because of its connection 1with secret codes, Lenstra made a breakthrough to a O(ec((log N )(log log N )) =2 ) method with c 2. Since then some progress has been made (Pollard reached O(e2((log N )(log log N ))1=3 ) but in spite of intense e orts mathematicians have not produced anything which would be a real threat to codes based on the factorisation problem. In 1996, it was possible to factor 100 (decimal) digit numbers routinely, 150 digit numbers with immense e ort but 200 digit numbers were out of reach. Organisations which use the RSA and related systems rely on `security through publicity'. Because the problem of cracking RSA codes is so notorious any breakthrough is likely to be publically announced16 . Moreover, even if a breakthrough occurs it is unlikely to be one which can be easily exploited by the average criminal. So long as the secrets covered by RSA-type codes need only be kept for a few months rather than forever, the codes can be considered to be one of the strongest links in the security chain.
ical community. 16 And if not, is most likely to be a government rather than a Ma a secret.
15 Although mathematically trained, Pollard worked outside the professional mathemat-
51
52
Obviously we should aim at the same kind of security as that o ered by our `level 2' for codes:Prospective opponents should nd it hard to nd H (M ) given M if they are in possession of a plentiful supply of message, signature pairs (Mi H (Mi)). of messages Mi together with their encodings Ci. I leave it to the reader to think about level 3 security (or to look at section 12.6 of 9]). Here is a signature scheme due to Elgamal. The message sender A chooses a very large prime p, some integer 1 < g < p. and some other integer u with 1 < u < p (as usual, some randomisation scheme should be used). A then releases the values of p, g and gu (modulo p) but keeps the value of u secret. Whenever he sends a message m (some positive integer) he chooses another integer k with 1 k p ; 2 at random and computes r and s with 1 r p ; 1 and 0 s p ; 2 by the rules18 r gk (mod p) (*)
m ur + ks (mod p ; 1)
(**)
gm yr rs (mod p) If A sends the message m followed by the signature (r s) the recipient need only verify the relation gm yr rs (mod p) to check that the message is authentic. Since k is random it is believed that the only way to forge signatures is to nd u from gu and it is believed that this problem, which is known as the discrete logarithm problem is very hard. Needless to say, even if it is impossible to tamper with a message, signature pair it is always possible to copy one. Every message should thus contain a unique identi er such as a time stamp. The evidence that the discrete logarithm problem is very hard is of the same kind of nature and strength as the evidence that the factorisation problem is very hard. We conclude our discussion with a description of the Di e{ Helman key exchange system which is also based on the discrete logarithm problem. 18 There is a small point which I have glossed over here and elsewhere. Unless k and and p ; 1 are coprime the equation (**) may not be soluble. However the quickest way to solve (**) if it is soluble is Euclid's algorithm which will also reveal if (**) is insoluble. If (**) is insoluble we simply choose another k at random and try again.
53
The modern coding schemes which we have discussed have the disadvantage that they require lots of computation. This is not a disadvantage when we deal slowly with a few important messages. For the Web where we must deal speedily with a lot of less than world shattering messages sent by impatient individuals this is a grave disadvantage. Classical coding schemes are fast but become insecure with reuse. Key exchange schemes use modern codes to communicate a new secret key for each message. Once the secret key has been sent slowly, a fast classical method based on the secret key is used to encode and decode the message. Since a di erent secret key is used each time, the classical code is secure. How is this done? Suppose A and B are at opposite ends of a tapped telephone line. A sends B a (randomly chosen) large prime p and a randomly chosen g with 1 < g < p ; 1. Since the telephone line is insecure A and B must assume that p and g are public knowledge. A now chooses randomly a secret number and tells B the value of g . B chooses randomly a secret number and tells A the value of g . Since g = (g ) = (g ) both A and B can compute k = g modulo p and k becomes the shared secret key. The eavesdropper is left with the problem of nding k g from knowledge of g, g and g (modulo p). It is conjectured that this is essentially as hard as nding and from the values of g, g and g (modulo p) and this is the discrete logarithm problem. We conclude with a quotation from Galbraith (referring to his time as ambassador to India) taken from Koblitz's entertaining text 5]. I had asked that a cable from Washington to New Delhi : : : be reported to me through the Toronto consulate. It arrived in code no facilities existed for decoding. They brought it to me at the airport | a mass of numbers. I asked if they assumed I could read it. They said no. I asked how they managed. They said that when something arrived in code, they phoned Washington and had the original read to them.
14 Further reading
For many students this will be the last university mathematics course they will take. Although the twin subjects of error-correcting codes and cryptography occupy a small place in the grand panorama of modern mathematics, it seems to me that they form a very suitable topic for such a nal course. 54
Outsiders often think of mathematicians as guardians of abstruse but settled knowledge. Even those who understand that there are still problems unsettled ask what mathematicians will do when they run out of problems. At a more subtle level Kline's magni cent Mathematical Thought from Ancient to Modern Times 4] is pervaded by the melancholy thought that though the problems will not run out they may become more and more baroque and inbred. `You are not the mathematicians your parents were' whispers Kline `and your problems are not the problems your parent's were.' However, when we look at this course we see that the idea of errorcorrecting codes did not exist before 1940. The best designs of such codes depend on the kind of `abstract algebra' that historians like Kline and Bell consider a dead end but lie behind the superior performance of CD players and similar artifacts. In order to go further into both codes, whether secret or error correcting we need to go into the the question of how the information content of a message is to be measured. `Information theory' has its roots in the code breaking of World War II (though technological needs would doubtless have lead to the same ideas shortly thereafter anyway). Its development required a level of sophistication in treating probability which was simply not available in the 19th century. (Even the Markov chain is essentially 20th century.) The question of what makes a calculation di cult could not even have been thought about until Godel's theorem (itself a product of the great `foundations crisis' at the beginning of the 20th century). Developments by Turing and Church of Godel's theorem gave us a theory of computational complexity which is still under development today. The question of whether there exist `provably hard' public codes is intertwined with still unanswered questions in complexity theory. There are links with the profound (and very 20th century) question of what constitutes a random number. Finally the invention of the electronic computer has produced a cultural change in the attitude of mathematicians towards algorithms. Before 1950, the construction of algorithms was a minor interest of a few mathematicians. (Gauss and Jacobi were consider unusual in the amount of thought they gave to actual computation.) Today we would consider a mathematician as much as a maker of algorithms as a prover of theorems. The notion of the probabilistic algorithm which hovered over much of our discussion of secret codes is a typical invention of the last decades of the 20th century. Although both subjects are now `mature' in the sense that they provide usable and well tested tools for practical application they still contain deep unanswered questions. For example How close to the Shannon bound can a `computationally easy' error correcting code get? 55
Do provably hard public codes exist? Even if these questions are too hard there must surely exist error correcting and public codes based on new ideas. Such ideas would be most welcome and, although they are most likely to come from the professionals they might come from outside the usual charmed circles. The best book I know for further reading is Welsh 9]. After this the book of Goldie and Pinch 7] provides a deeper idea of the meaning of information and its connection with the topic. The book by Koblitz 5] develops the number theoretic background. The economic and practical importance of transmitting, storing and processing data far outweighs the importance of hiding it. However, hiding data is more romantic. For budding cryptologists and cryptographers (as well as those who want a good read) Kahn's The Codebreakers 2] has the same role as is taken by Bell's Men of Mathematics. for budding mathematicians.
References
1] U. Eco The Search for the Perfect Language (English translation), Blackwell, Oxford 1995. 2] D. Kahn The Codebreakers: The Story of Secret Writing MacMillan, New York, 1967. (A lightly revised edition has recently appeared.) 3] D. Kahn Seizing the Enigma Houghton Mi in, Boston, 1991. 4] M. Kline Mathematical Thought from Ancient to Modern Times OUP, 1972. 5] N. Koblitz A Course in Number Theory and Cryptography Springer, 1987. 6] D. E. Knuth The Art of Computing Programming Addison-Wesley. The third edition of Volumes I to III is appearing during this year and the next (1998{9). 7] G. M. Goldie and R. G. E. Pinch Communication Theory CUP, 1991. 8] T. M. Thompson From Error-correcting Codes through Sphere Packings to Simple Groups Carus Mathematical Monographs 21, MAA, Washington DC, 1983. 9] D. Welsh Codes and Cryptography OUP, 1988. 56
the probability p of error to be less than 1=2. Why do we not consider the case 1 p > 1=2? What if p = 1=2? Q 15.2. Do Exercise 2.3 Machines tend to communicate in binary strings so this course concentrates on binary alphabets with two symbols. There is no particular di culty in extending our ideas to alphabets with n symbols though, of course, some tricks will only work for particular values of n. If you look at the inner title page of almost any recent book you will nd its International Standard Book Number (ISBN). The ISBN uses single digits selected from 0, 1, : : : , 8, 9 and X representing 10. Each ISBN consists of nine such digits a1 , a2 , : : : , a9 followed by a single check digit a10 chosen so that 10a1 + 9a2 + + 2a9 + a10 0 mod 11: (*) (In more sophisticated language our code C consists of those elements a 2 F 10 11 P such that 10 (11 ; j )aj = 0.) j =1 (i) Find a couple of books and check that ( ) holds for their ISBNs. (ii) Show that ( ) will not work if you make a mistake in writing down one digit of an ISBN. (iii) Show that ( ) may fail to detect two errors. (iv) Show that ( ) will not work if you interchange two adjacent digits. Errors of type (ii) and (iv) are the most common in typing. Q 15.3. Do Exercise 2.4 Suppose we use eight hole tape with the standard paper tape code and the probability that an error occurs at a particular place on the tape (i.e. a hole occurs where it should not or fails to occur where it should) is 10;4. A program requires about 10 000 lines of tape (each line containing eight places) using the paper tape code. Using the Poisson approximation, direct calculation (possible with a hand calculator but really no advance on the Poisson method) or otherwise show that the probability that the tape will be accepted as error free by the decoder is less than .04%. Suppose now that we use the Hamming scheme (making no use of the last place in each line). Explain why the program requires about 17 500 lines of tape but that any particular line will be correctly decoded with probability 57
about 1 ; (21 10;8) and the probability that the entire program will be correctly decoded is better than 99.6%. Q 15.4. Show that if 0 < < 1=2 there exists an A( ) > 0 such that whenever 0 r n we have
r X n j =0
A( ) n : r
(We use weaker estimates in the course but this is the most illuminating. Q 15.5. Show that the n-fold repetition code is perfect if and only if n is odd. Q 15.6. Let C be the code consisting of the word 10111000100 and its cyclic shifts (that is 01011100010, 00101110001 and so on) together with the zero code word. Is C linear? Show that C has minimum distance 5. Q 15.7. Write down the weight enumerators of the trivial code, the repetition code and the simple parity code. Q 15.8. List the codewords of the Hamming (7,4) code and its dual. Write down the weight enumerators and verify that they satisfy the MacWilliams identity. Q 15.9. (a) Show that if C is linear then so are its extension C +, truncation C ; and puncturing C 0 provided the symbol chosen to puncture by is 0. (b) Show that extension and truncation do not change the size of a code. Show that it is possible to puncture a code without reducing the information rate. (c) Show that the minimum distance of the parity extension C + is the least even integer n with n d(C ). Show that the minimum distance of C ; is d(C ) or d(C ) ; 1. Show that puncturing does not change the minimum distance. Q 15.10. If C1 and C2 are of appropriate type with generator matrices G1 and G2 write down a generator matrix for C1jC2. Q 15.11. Show that the weight enumerator of RM (d 1) is
58
X = fx 2 F 90 : x1 = 1 x2 = 1 d(0 x) = 3g: 2
Show that corresponding to each x 2 X we can nd a unique c(x) 2 C such that d(c(x) x) = 2. (iv) Continuing with the argument of (iii) show that
d(c(x) 0) = 5
and that ci(x) = 1 whenever xi = 1. By looking at d(c(x) c(x0)) for x x0 2 X and invoking the Dirichlet pigeon-hole principle, or otherwise, obtain a contradiction. (v) Conclude that there is no perfect 90 278] code.
59
Q 16.1. An erasure is a digit which has been made unreadable in transmission. Why are they easier to deal with than errors? Find a necessary and su cient condition on the parity check matrix of a linear (n k) code for it to be able to correct t erasures and relate t to n and k in a useful manner. Q 16.2. Consider the collection K of polynomials
a0 + a1 ! + a2 !2
with aj 2 F2 manipulated subject to the usual rules of polynomial arithmetic and the further condition 1 + ! + !2 = 0: Show by direct calculation that F = F n f0g is a cyclic group under multiplication and deduce that K is a nite eld. Of course, this follows directly from general theory but direct calculation is not uninstructive.] Q 16.3. (i) Identify the cyclic codes of length n corresponding to each of the polynomials 1, X ; 1 and X n;1 + X n;2 + + X + 1. (ii) Show that there are three cyclic codes of length 7 corresponding to irreducible polynomials of which two are versions of Hamming's original code. What are the other cyclic codes? (iii) Identify the dual codes for each of the codes in (ii). Q 16.4. Do Example 7.15. (i) If K is a eld containing F 2 then (a + b)2 = a2 + b2 for all a b 2 K . (ii) If P 2 F 2 X ] and K is a eld containing F 2 then P (a)2 = P (a2) for all a 2 K . (iii) Let K be a eld containing F 2 in which X 7 ; 1 factorises into linear factors. If is a root of X 3 + X + 1 in K then is a primitive root of unity and 2 is also a root of X 3 + X + 1. (iv) We continue with the notation (iii). The BCH code with f 2g as de ning set is Hamming's original (7,4) code. 60
xn =
d X j =1
bj
n j
for some bj 2 K . If x0 x1 : : : xd;1 2 F 2 then xn 2 F 2 for all n. (iii) Work out the rst few lines of Pascal's triangle modulo 2. Show that the functions fj : Z ! F 2
aj fj (n) = 0 m.
61
(iv) Suppose K is a eld containing F 2 such that the auxiliary polynomial C factorises completely into linear factors. If the root u has multiplicity mu 1 u q] then the general solution of ( ) in K is
xn =
bu v n v
n u
for some bu v 2 K . If x0 x1 : : : xd;1 2 F 2 then xn 2 F 2 for all n. Q 16.8. Do Exercise 10.8 One of the most con dential German codes (called FISH by the British) involved a complex mechanism which the British found could be simulated by two loops of paper tape of length 1501 and 1497. If kn = xn + yn where xn is a stream of period 1501 and yn is stream of period 1497 what is the longest possible period of kn? How many consecutive values of kn do you need to to specify the sequence completely? Q 16.9. We work in F2 . I have a secret sequence k1, k2, : : : and a message p1 , p2, : : : , pN . I transmit p1 + k1 , p2 + k2, : : : pN + kN and then, by error, transmit p1 + k2, p2 + k3, : : : pN + kN +1 . Assuming that you know this and that my message makes sense how would you go about nding my message? Can you now decipher other messages sent using the same part of my secret sequence? Q 16.10. Give an example of a homomorphism attack on an RSA code. Show in reasonable detail that the Elgamal signature scheme defeats it. Q 16.11. I announce that I shall be using the Rabin-Williams scheme with modulus N . My agent in X'Dofdro sends me a message m (with 1 m N ; 1) encoded in the requisite form. Unfortunately my cat eats the piece of paper on which the prime factors of N are recorded so I am unable to decipher it. I therefore nd a new pair of primes and announce that I shall be using the Rabin Williams scheme with modulus N 0 > N . My agent now recodes the message and sends it to me again. The dreaded SNDO of X'Dofdro intercept both code messages. Show that they can nd m. Can they decipher any other messages sent to me using only one of the coding schemes? Q 16.12. Extend the Di e-Helman key exchange system to cover three participants in a way that is likely to be as secure as the two party scheme. Extend the system to n parties in such a way that they can compute their common secret key in at most n2 ; n communications. 62