Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
[Fred_Piper]_Cryptography_A_Very_Short_Introducti(BookFi.org).pdf
Скачиваний:
94
Добавлен:
12.03.2016
Размер:
1.89 Mб
Скачать

Appendix

Team-Fly

Appendix

Introduction

In this appendix we discuss two basic mathematical ideas; binary representations of integers and modular arithmetic. Both play crucial roles in cryptography. Binary numbers are often taught in schools. Modular arithmetic is not so widely taught but, for special values like 7 and 12, it is a process which people do naturally.

Binary numbers

When writing an integer in decimal we use, essentially, a units' column, a tens' column, a hundreds' column, a thousands' column, and so on. Thus 3,049 is 3 thousands, 0 hundreds, 4 tens and 9 units. For decimal numbers we are working with base 10 and the columns represent the

powers of 10, so 100 = 1, 101 = 10, 102 = 100, 103 = 1,000 and so on.

In binary numbers we work with base 2. The basic digits are 0 and 1 and we have a units' column, a twos' column, a fours' column

(remember 4 = 22 ), an eights' column (8 = 23) and so on. This now means that every binary string can be regarded as a number. For example, 101 in binary is 1 four, 0 twos, and 1 one, so the binary string 101 represents 4 + 0 + 1 = 5 in decimal. Similarly 1011 in binary is 1 eight, 0 fours, 1 two and 1 one. Thus the binary string 1011 = 8 + 0 + 2 + 1 = 11 in decimal. As one last example consider 1100011. This time we have 7 columns. The powers of 2 are 1, 2, 4, 8, 16, 32, 64 and so the binary string 1100011 represents 64 + 32 + 0 + 0 + 0 + 2 + 1 = 99 in decimal.

Clearly any positive integer can be written in binary form and there are many ways of determining this form. We illustrate one method by doing a couple of examples. Suppose we wish to find the binary representation of 53. The powers of 2 are 1, 2, 4, 8, 16, 32, 64 ... However, we can stop at 32 because all the other powers are bigger than 53. Now 53 = 32 + 21. But 21 = 16 + 5 and 5 = 4 + 1. So 53 = 32 + 16 + 4 + 1. All we have done is written 53 as the sum of powers of 2. We now note that 53 = (1 x 32) + (1 x 16) + (0 x 8) + (1 x 4) + (0 x 2) + (1 x 1) and so 53 = 110101 in binary. For a second example consider 86. This time the highest power of 2 we need is 64. Repeating the earlier reasoning, we see that 86 = 64 + 16 + 4 + 2. Thus 86 is 1010110 in binary.

The term bit is a contraction of binary digit. When we refer to an n-bit number, we mean that its binary form requires n bits. Thus, in the above examples, 53 is a 6-bit number and 86 is a 7-bit number. In general, 3.32d gives some idea of the number of bits needed to express d decimal digits in binary.

Modular arithmetic

Modular arithmetic is only concerned with integers, commonly known as whole numbers. If N is a positive integer, then arithmetic modulo N uses only the integers 0, 1, 2, 3,..., N-1, that is, integers from 0 to N-1.

There are a number of values of N for which arithmetic modulo N is common to most people, although they may not be familiar with the mathematical terminology. For instance when we use a 12-hour clock we use addition modulo 12. If it is now 2 o'clock then everyone 'knows' that the time in 3 hours is 5 o'clock, as it will also be in 15 hours. This is because 15 = 12 + 3 and the time repeats every 12 hours. Other natural numbers are N = 7 (for the days of the week) and N = 2 (for odd and even).

If two numbers have the same remainder on division by N, we regard them as being equal modulo N. For example, if N = 7, then, since 9 = (1 x 7) + 2 and 23 = (3 x 7) + 2, we regard 9 and 23 as being equal modulo 7. If x and y are equal modulo N then we write x = y (mod N). Note then every integer must be equal modulo N to one of the values 0, 1, 2,..., N-1.

As an illustration of the use of modular arithmetic, suppose that the first day of a month is on a Tuesday. Then clearly the 2nd will be a Wednesday, the 3rd a Thursday, and so on. What about the 29th? One way of answering the question is to consult a calendar or to write out the days for the complete month. Another is to observe that the pattern of days repeats every 7 days. So, clearly, the 8th day is also a Tuesday. Now we note that 29 = 4 x 7 + 1 which, using the notation above, says 29 = 1 (mod 7). Thus the 29th is exactly 4 weeks after the 1st and falls on a Tuesday. A similar argument shows that, since 19 = 2 x 7 + 5, the 19th will be a Saturday.

Once we have introduced the concept of working modulo N, then the arithmetic processes are straightforward. For example, if N = 11 then 5 x 7 = 2 (mod 11) since 5 x 7 = 35 = (3 x 11) + 2. We can also write equations modulo N. So, for example, solve 3x = 5 (mod 8) means find a

file:///D|/1/4303/Fly0017.html (1 von 2) [08.10.2007 12:51:10]

Appendix

value x such that the product of 3 with x is equal to 5 modulo 8. The solution to this particular equation is x = 7. It is beyond the scope of this appendix to provide methods to solve this type of equation. However, it is easy to verify that x = 7 satisfies 3x = 5 (mod 8) because 3 x 7 = 21= 2 x 8 + 5. When talking about modular arithmetic it is important to remember that we are only 'allowed' to use integers, that is whole numbers. In particular if we are asked to solve an equation like 3x = 5 (mod 8), then the answer must be an integer between 0 and 7.

One of the main reasons for including an introduction to modular arithmetic is that the two most popular public key algorithms use modular

exponentiation as their basic mathematical process. Modular exponentiation means nothing more than computing xa (mod N) for given integers x, a, N. Suppose x = 5, a = 4, and N = 7.

Then 54 = 5 x 5 x 5 x 5 = 625 = (89 x 7) + 2, so 54 = 2 (mod 7). There is no need for anyone using cryptography to be able to perform these calculations, but it almost certainly helps to understand the notation.

When discussing the Caesar Cipher we introduced additive ciphers, the notion of assigning numbers to the letters of the alphabet and then using arithmetic modulo 26. A close inspection of the Vigenère Square shows that the first row, used for key letter a, represents the additive cipher with shift 0, while the second row, determined by key letter b, represents an additive cipher with shift 1 and so on. In fact if we associate A = 0, B = 1,..., Z = 25 then each key letter merely indicates the use of an additive cipher with shift equal to its associated value. This simple observation may prove helpful to anyone who tries to write a program to implement a Vigenère Cipher.

Our discussion of additive ciphers was followed by an introduction of the notion of a multiplicative cipher where we listed those numbers which can be used as keys. Although it may not be clear how we obtained the list, it is straightforward to check that the list is correct. For each of the numbers 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25, when we multiply the 26 letters of the alphabet by that number, we get 26 different answers. This means that the number can be used as the encryption key for a multiplicative cipher. The corresponding decryption keys are listed below and, once again, although it may not be apparent how they were calculated, it is straightforward to check that they are correct. The effect of multiplying by an encryption key and then multiplying by the corresponding decryption key should be to leave the letters unchanged, which is equivalent to multiplying by 1. For example, to check that, for an encryption key of 3, the decryption key is 9, we need only show that 3 x 9 =1 (mod 26), which, since 3 x 9 = 27 = 26 + 1, is true.

Encryption key

1

3

5

7

9

11

15

17

19

21

23

25

Decryption key

1

9

21

15

3

19

7

23

11

5

17

25

Team-Fly

file:///D|/1/4303/Fly0017.html (2 von 2) [08.10.2007 12:51:10]