
































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































































Introduction
These are the lecture notes for the modules G13CCR, Coding and Cryptography, as given in the spring semester 2013 at the University of Nottingham. Cryptography is the art (or the science) of encrypting messages so that no other than the authorised person can decrypt and read the message. What is coding theory then? It is something quite different. There are many sorts of code and we will only discuss one type, namely error-correction codes. Other codes are used for compression, but they are (no longer) part of this module. There is a conceptual, mathematical approach called Information Theory, which treats the subjects like entropy and information in transmissions. This module consists of two parts, one on error-correction codes and one on cryptogra- phy.
The software for early computer had to be fed to the machine using long paper tape, later came the magnetic tapes. Each character was stored as 7 bits, plus an additional bit, the parity check bit. Simply this last bit was a 1 if within the the 7 bits there were an odd number of 1’s. In this way it was possible to check if there was an error. Maybe one bit was not recorded correctly or it was not read correctly. Of course, if two errors appeared in one single block of 7 bits the parity check could not detect the errors. Moreover, even if a single error in the block has been transmitted, there is no way to recover the correct block, as any of the seven bit could have been wrong. This lead Hamming to discover error-correcting codes. Here is another simple example, the International Standard Book Number ISBN. Any book has a unique code, e.g. the book ‘Coding Theory’ by San Ling and Chaoping Xing [11] is listed as 0-521-52923-9. The last digit of this code is a check digit. If the previous digits are x 1 , x 2 ,... , x 9 , then the last digit is computed as
x 10 = 1 · x 1 + 2 · x 2 + 3 · x 3 + · · · + 9 · x 9 mod 11 ,
where ‘mod 11’ indicates that we replace the result by the remainder when dividing by
9 ≡ 1 · 0 + 2 · 5 + 3 · 2 + 4 · 1 + 5 · 5 + 6 · 2 + 7 · 9 + 8 · 2 + 9 · 3 (mod 11).
Coding and Cryptography G13CCR cw ’
Suppose I made an error when copying the code, e.g. I confused the 1 at the fourth position with a 7. Then the sum above would give
0 ≡ 1 · 0 + 2 · 5 + 3 · 2 + 4 · 7 + 5 · 5 + 6 · 2 + 7 · 9 + 8 · 2 + 9 · 3 (mod 11) ,
so we know that there is an error. But the code is even better, suppose I swapped the 2 and 3 in the eighth and ninth position, then again my sum will give a different value as the coefficients are different:
8 ≡ 1 · 0 + 2 · 5 + 3 · 2 + 4 · 1 + 5 · 5 + 6 · 2 + 7 · 9 + 8 · 3 + 9 · 2 (mod 11).
Again, this code still does not tell us where the error is; also if we made two errors it may well be that the sum equal the check digit. Error-correcting codes are extremely important in modern telecommunication. When the reception of your mobile is very poor, the antenna does not receive correctly all infor- mation your phone has sent. It is then important to be able to recover your message from the partial information that the antenna received. Another example is data storage. Using magnetic disk as an example, if you were to look at bits coming right off a magnetic disk you would see, on the average, about 1 bit error for every 10^9 bits transferred, i.e. as frequent as every 25 seconds. If you were to look at bits coming right off an optical disk, you would see a much higher rate of errors, about 1 bit error in every 10^5 bits transferred. Without some form of error detection and correction, most storage devices would be too unreliable to be useful. (Source [22])
Cryptography originally deals with the problem of encrypting messages so that nobody but the authorised person can decrypt and read it. It has been used throughout the last 2000 years, but the methods and the problematic have become more and more elaborate. Often codes that were believed to guarantee secrecy were in fact not too difficult to break. Here a text in which Casanova explains how he decrypted a text much to the surprise of Madame d’Urf´e.
J’avais fini par connaˆıtre a fond Mme d’Urf´e qui me croyais fermement un adepte consomm´e sous le masque de l’incognito, et cinq ou six semaines apres elle se confirma dans cette id´ee chim´erique, lorsqu’elle me demanda si j’avais d´echiffr´e le manuscrit ou se trouvait la pr´etendue explication du Grand-Œuvre. «Oui, lui-dis-je, je l’ai d´echiffr´e et par cons´equent lu ; mais je vous le rends en vous donnant ma parole d’honneur que je ne l’ai pas copi´e, car je n’y ai trouv´e rien de nouveau. — Sans la clef, monsieur, excusez-moi, mais je crois la chose impossible. — Voulez-vous, madame, que je vous nomme la clef? — Je vous en prie. » Je lui donne la parole, qui n’´etait d’aucune langue, et voila ma marquise tout ´ebahie. «C’est trop, monsieur, c’est trop! je me croyais seule en possession de ce mot myst´e- rieux, car je le conserve dans ma m´emoire, je ne l’ai jamais ´ecrit et je suis certaine de ne l’avoir jamais donn´e `a personne. »
Coding and Cryptography G13CCR cw ’
The last entry is typically very important if you buy an online insurance policy and you want to make a claim, but the insurance company claims you have never signed a policy with them. The authenticity is crucial when you use online banking as you want to be certain that the site you are communicating with is indeed your bank and not some phishing site.
These course notes are largely based on Dr. Woodall’s previous notes for this course, but I enlarged and modified quite a lot using sources like [11], [4], Tom K¨orner’s course [9], Peter Symonds’ course [18] and wikipedia, of course. I would also like to thank Edward Hobbs for many correction of the earlier version. All computations for this course as well as all plots were made using the computer algebra package sage [17], which itself uses pari-gp [14]. This is free, open-source software comparable to maple, matlab, mathematica or magma. See in particular [7] and [13] for more details how to use sage for coding and cryptography.
Chapter I
Error-Correcting Codes
The aim of error-correcting codes is to add redundancy to a message in order to be able correct errors that may occur during the transmission of the message.
Throughout the whole chapter on error-correction codes will be in the following situation. See also figure I.1.
(^1) In other words, we assume to work only with the binary alphabet; it is not hard to generalise to arbitrary alphabets but we will stick to the easiest situation here.
cw ’13 Coding and Cryptography G13CCR
change the one copy that is different. Say we receive x =‘ 0 10110110’, we will just change the starting 0 back to a 1. Of course, this may go wrong. In the very, very unlikely case that two errors occurred and that they happen to change the same bit, e.g. if we receive x =‘ 0100 10110’ we would change the last copy instead and then decode to the wrong sourceword w′^ =‘010’.
This is a very bad code as we will see later. It has some strength for correcting errors, but its rate 13 is very bad. All the transmission is slowed down to a third of the uncoded speed.
A few more words on the channel^2. The only symbols that can be transmitted are 0 and
P (1 received |0 sent) = P (0 received |1 sent) = p P (0 received |0 sent) = P (1 received |1 sent) = 1 − p.
Diagrammatically:
1 −p (^) //
p ) ) RRRR RRRR RRRR
RRRR
(^1 1) −p //
p
55 llll llll llll llll ll 1
We shall assume^3 that p < 12. Examples of such noisy channels include digital radio transmission, e.g. for mobile phones and Wireless LAN, but also digital transmission through optical fibres and traditional electrical cables. But we can also include storage devices as the channel which starts at the computer writes on a magnetic disk and reads off it later again. As mentioned in the introduction, a Compact Disk has read with probability p = 10−^5 the wrong bit; while for a magnetic disk the error probability is as low as p = 10−^9.
The probability that a word of length n is sent through the channel with some corruption is 1−(1−p)n, which for small p is approximately n·p. The probability that errors occurred at d given places in the word is equal to pd^ · (1 − p)n−d.
Finally, we make an assumption^4 on the source: We suppose that all sourcewords appear with approximately the same frequency and that the probability is not influenced by the word previously sent. This is typically not the case in a language like English as words like ‘the’ are much more frequent than others. In reality this is not always the case, but it can be achieved by first using a compression algorithm, e.g. “zip” the file. In any case, the restriction is not a serious one.
(^2) Such a channel is called a binary symmetric channel with crossover probability p. (^3) Why? Well, try to think what you would do if p > 1
Coding and Cryptography G13CCR cw ’
In this section we will find the best error-correction method. What we hope for is that c′^ = c (referring to the notation in this figure I.1) as then w = w′. If the received word w is not a codeword, we wish to interpret it as the codeword most likely to have been sent. Intuitively, this is the codeword closest to w.
Definition. If x, y ∈ Vn, their Hamming distance d(x, y) is the number of positions in which they differ. The weight w(x) of x is the number of 1’s in x.
So w(x) = d(x, 0 ), where 0 = (0, 0 ,... , 0) is the word with n zeroes. For example, the distance between
x = ( 1 , 0, 0 , 1 , 1, 0) and y = ( 0 , 0, 1 , 0 , 1, 0)
is d(x, y) = 3. The function d : Vn → N ∪ { 0 } satisfies the axioms of a metric, which are
Theorem I.1. When a word x ∈ Vn is received, the codewords c ∈ C that are most likely to have been sent are those for which d(c, x) is smallest.
Proof. Let x be a fixed source word. By Bayes’s theorem,
P (c sent | x received ) = P (c sent, x received ) P (x received )
= P (c sent ) · P (x received | c sent ) P (x received )
holds for any code word c. Let
h = P (c sent ) P (x received )
which is independent of c, since we are assuming that all codewords are equally likely. By the definition of the distance d = d(c, x), the probability that x was received, knowing that c was sent is pd^ · (1 − p)n−d. Thus
P (c sent | x received ) = h · P (x received | c sent )
= h · pd^ · (1 − p)n−d^ = h · (1 − p)n^ ·
( (^) p 1 − p
)d ,
which is largest when d = d(c, x) is smallest, since we are assuming that p < 12 and so p 1 −p <^ 1.
Coding and Cryptography G13CCR cw ’
we correct the error. In the last example, the closest word is 0101010 rather than c. So by choosing the code word that was most likely sent, we would actually pick^6 the wrong. See [26] for more pictures and descriptions on this code. In general it might happen (though not for this code) that there are two or more code words among those closest to the received word, in which case we would have to choose randomly among these and make a mistake with a certain likeliness.
Definition. A code is e-error-detecting if it can detect that there is a mistake whenever e or fewer errors are made in any one codeword. It is said to be e-error-correcting if it can correct these errors. The minimum distance of a code C is
d(C) := min
d(c, c′)
∣ (^) c 6 = c′^ ∈ C}^.
It is easy to see that C is e-error-detecting if and only if d(C) > e + 1 and that C is e-error-correcting if and only if d(C) > 2 e + 1. So the proof of the following lemma is obvious.
Lemma I.2. A code C of minimum distance d(C) can detect d(C) − 1 errors and correct b d(C 2 ) −^1 c errors, but it cannot do any better than that.
'
&
$
% (a) e-error-detecting
'
&
$
% (b) e-error-correcting
Figure I.2: Two Potatoes
In an illustrative drawing, we can draw the two pictures in figure I.2. The red dots in the centre of the circles represent the code words in Vn, which is drawn as a potato. The blue circle represent the balls of radius e centred at the code-words. A code is e-error detecting if each ball contains a unique code word. If the circles do not intersect at all, then the code is e error-correcting. Example. Hamming’s code in the previous example has minimum distance d(C) = 3. It is therefore 2-error-detecting and 1-error-correcting.
Notation. A [n, k, d]-code is a code of length n with 2k^ codewords^7 and minimum dis- tance d. (^6) The German word ‘verschlimmbessern’ describes well how we ‘disimproved’ the error. (^7) You will also find the notation (n, 2 k (^) , d) instead in the literature.
cw ’13 Coding and Cryptography G13CCR
As seen in figure I.2, it is natural to consider the (closed) Hamming balls
B(x, r) =
y ∈ Vn
d(x, y) 6 r
Observe that the balls for varying x have all the same size; in fact, since all y of distance j to x are obtained by switching j coordinates in x, there are exactly
(n j
such y, and hence
#B(x, r) =
∑^ r
j=
n j
It is now easy to prove a first bound on codes.
Theorem I.3 (Sphere packing bound). If C is a an e-error correcting code in Vn then
2 n ∑e j=
(n j
Proof. Each word in Vn appears in at most one of the #C balls of radius e around the code-words. So #C · #B(x, e) 6 #Vn gives the result.
Definition. A code is perfect if we have an equality in formula (I.3).
In other words, a code is perfect if the balls of radius e around the codewords fill out all of Vn without intersecting. Perfect codes do not exist for all n and e, since the right hand side of (I.3) is not always an integer. The following codes are further perfect codes.
Theorem I.4 (The Singleton^8 bound). Let C be a [n, k, d] code, then d 6 n − k + 1.
(^8) Named after R. C. Singleton and not the mathematical notion of a set with one single element.
cw ’13 Coding and Cryptography G13CCR
(just as for 0, 1 ∈ R except that 1 + 1 = 0). Of course this is the unique field structure on a set of two elements. Note that a + a = 0 for all a ∈ F 2 , so addition and subtraction are the same: a = −a, and a + b = a − b. Now Vn, the set of binary words of length n, is a n-dimensional vector space over F 2. We will always write elements of Vn as row vectors. Addition in Vn is defined coordinate-wise, like
x = (0, 0, 1, 1, 0, 1)
The scalar multiplication is defined in the obvious way
0 · x = 0 and 1 · x = x
with 0 being the zero vector 0 = (0, 0 ,... , 0).
Lemma I.6. For a non-empty set X in Vn it is enough to check that it is closed under addition to assure that it is a linear subspace.
Proof. Suppose X is a non-empty subset of Vn which is closed under addition. In order to prove that X is a linear subspace, we have to make sure that it is also closed under scalar multiplication. Indeed, if x ∈ X then x + x = 0 ∈ X and hence, for any x ∈ X and any λ ∈ F 2 , we have λ · x ∈ X.
As usual, we have the scalar product
x · y = x 1 · y 1 + x 2 · y 2 + · · · + xn · yn
with values in F 2 ; e. g.
(1, 0 , 1 , 1 , 0 , 1 , 1) · (0, 0 , 1 , 1 , 0 , 1 , 0) = 0 + 0 + 1 + 1 + 0 + 1 + 0 = 1.
It satisfies the usual properties
x · y = y · x, x · (y + z) = x · y + x · z, and (λx) · y = λ (x · y).
Definition. If X is a subset of Vn, we define the orthogonal complement by
X⊥^ =
y ∈ Vn
∣ (^) x · y = 0 for all x ∈ X}^.
Theorem I.7. If X is a subspace of Vn of dimension k, then X⊥^ is a subspace of dimension n − k.
Coding and Cryptography G13CCR cw ’
Proof. Clearly x · 0 = 0 for all x, so 0 ∈ X⊥. For any y, z ∈ X⊥, we have
x · (y + z) = x · y + x · z = 0 + 0 = 0
for all x ∈ X. So y + z ∈ X⊥, hence X⊥^ is a subspace. Now let
x 1 = (x 11 , x 12 ,... , x 1 n) x 2 = (x 21 , x 22 ,... , x 2 n) .. .
xk = (xk 1 , xk 2 ,... , xkn)
be a basis of X. Then y = (y 1 , y 2 ,... , yn) belongs to X⊥^ if and only if
x 11 x 12 · · · x 1 n x 21 x 22 · · · x 2 n .. .
xk 1 xk 2 · · · xkn
y 1 y 2 .. . yn
The coefficient matrix has rank k. Since X⊥^ is the solution space to this equation it must be of dimension n − k, as required.
Corollary I.8. (X⊥)⊥^ = X.
Proof. Since x · y = 0 for each x in X and y in X⊥, clearly X ⊂ X⊥⊥. But, by the previous theorem I.7,
dim X⊥⊥^ = n − dim X⊥^ = n − (n − k) = k = dim X,
and so X⊥⊥^ = X.
A linear code (of dimension k and length n) is a code C that is a k-dimensional subspace of Vn. The distance d(C) of a linear code is now simply
d(C) = min
w(c)
∣ (^0 6) = c ∈ C}^ (I.4)
since w(x − y) = d(x, y). Almost all codes used in practice are linear, because:
Coding and Cryptography G13CCR cw ’
Recall that the kernel of H is the set of all solutions of the system of linear equations Hxt^ = 0 t. So the parity-check matrix H can be used to give a criterion: A vector x belongs to C if and only if H xt^ = 0 t^ or, in other words, if and only if x ∈ D⊥, where D is the subspace generated by the rows of H. Often, we will be in the situation where the rows of H are linearly independent, in which case there are n − k of them. Both G and H have always n columns. Example. Giving a parity check matrix for a code is the same as listing linear equations that are satisfied by all elements of C. For the Hamming code given by the equations I. it is easy to write out a parity check matrix just by copying these equations.
By solving the equations I.5, we find easily four linearly independent vectors in C. We get a generator matrix by putting them in a matrix as rows.
In fact, I have taken the image under the encoding map in (I.2) (which happens to be a linear map) of the obvious basis in V 4. So this G corresponds to this encoding map. Since all rows in G are orthogonal to the rows in H, we have the matrix equation H · Gt^ = 0. Here 0 is the zero-matrix. Clearly rank(G) = dim C = k and rank(H) = dim D = n − k by theorem I.7, since C = D⊥^ and hence, by corollary I.8, D = D⊥⊥^ = C⊥.
Definition. C⊥^ is the dual code of C.
If G and H are a generator matrix and a parity check matrix for C, respectively, then H is a generator matrix for C⊥^ and G is a parity-check matrix for it.
It is obvious from the previous section that there are several choices of generator and parity check matrices for a linear code C. Here we describe a way of getting them in a standard form.
Definition. Two linear codes are equivalent if one can be obtained by applying the same position-wise permutation of bits to all the codewords in the other.
The quality (rate and distance) of two equivalent codes are the same. For all practical purposes, we can exchange a code with an equivalent code without changing the important properties.
cw ’13 Coding and Cryptography G13CCR
Theorem I.9. By replacing C by an equivalent code if necessary, we can choose
G =
Ik A
and H =
At^ In−k
for some k × (n − k) matrix A. The generator matrix G is then said to be in standard form.
Proof. Let G be a k × n generator matrix for C. Note that elementary row operations on G do not change C, while permuting the columns corresponds to permuting the bits so as to give a code equivalent to C. Also, we may assume that no row of G is all zero. So permute the columns to ensure g 11 = 1, then add row 1 to other rows as necessary to clear the first column apart from g 11. Now permute columns 2,... , n to ensure g 22 = 1, then operate with row 2 to clear the second column apart from g 22. And so on.^11 Given G =
Ik A
in standard form, define H =
At^ In−k
. It clearly has rank n − k, and so it suffices to show that every row of G is orthogonal to every row of H. But the dot product of the ith^ row of G with the jth^ row of H is
0 + 0 + · · · + 0 + aij + 0 + · · · + 0 + aij + 0 + · · · + 0 = 0.
In matrix equations, we can also write
H Gt^ =
At^ In−k
Ik At
= At^ + At^ = 0.
As an example, we treat again Hamming’s code. We start with the matrix G in (I.7). We add the first row to the last two rows.
Then add the second row to the first and the third.
Now we swap the last two rows.
(^11) In practice it is preferable to permute rows rather than columns, since this does not change C; but it will not always work.