54
2.1 Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

Embed Size (px)

DESCRIPTION

Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic. 2-1 INTEGER ARITHMETIC. In integer arithmetic, we use a set and a few operations. You are familiar with this set and the corresponding operations, but they are reviewed here to create a background for modular arithmetic. - PowerPoint PPT Presentation

Citation preview

Page 1: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.1

Chapter 2

Mathematics of CryptographyPart I: Modular Arithmetic

Page 2: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.2

2-1 INTEGER ARITHMETIC2-1 INTEGER ARITHMETIC

In integer arithmetic, we use a set and a few In integer arithmetic, we use a set and a few operations. You are familiar with this set and the operations. You are familiar with this set and the corresponding operations, but they are reviewed here corresponding operations, but they are reviewed here to create a background for modular arithmetic.to create a background for modular arithmetic.

2.1.1 Set of Integers2.1.2 Binary Operations2.1.3 Integer Division2.1.4 Divisibility

Topics discussed in this section:Topics discussed in this section:

Page 3: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.3

The set of integers, denoted by Z, contains all integral numbers (with no fraction) from negative infinity to positive infinity (Figure 2.1).

2.1.1 Set of Integers

Figure 2.1 The set of integers

Page 4: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.4

In cryptography, we are interested in three binary operations applied to the set of integers. A binary operation takes two inputs and creates one output.

2.1.2 Binary Operations

Figure 2.2 Three binary operations for the set of integers

Page 5: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.5

Example 2.1

2.1.2 Continued

The following shows the results of the three binary operations The following shows the results of the three binary operations on two integers. Because each input can be either positive or on two integers. Because each input can be either positive or negative, we can have four cases for each operation.negative, we can have four cases for each operation.

Page 6: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.6

In integer arithmetic, if we divide a by n, we can get qAnd r . The relationship between these four integers can be shown as

2.1.3 Integer Division

a = q × n + r

Page 7: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.7

Assume that a = 255 and n = 11. We can find q = 23 and R = 2 using the division algorithm.

2.1.3 Continued

Figure 2.3 Example 2.2, finding the quotient and the remainder

Example 2.2

Page 8: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.8

2.1.3 ContinuedFigure 2.4 Division algorithm for integers

Page 9: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.9

Example 2.3

2.1.3 Continued

When we use a computer or a calculator, When we use a computer or a calculator, rr and and qq are negative are negative when when aa is negative. How can we apply the restriction that is negative. How can we apply the restriction that r r needs to be positive? The solution is simple, we decrement the needs to be positive? The solution is simple, we decrement the value of value of qq by 1 and we add the value of by 1 and we add the value of nn to to rr to make it to make it positive.positive.

Page 10: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.10

If a is not zero and we let r = 0 in the division relation, we get

2.1.4 Divisbility

a = q × n

If the remainder is zero,

If the remainder is not zero,

Page 11: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.11

Example 2.4

2.1.4 Continued

a.a. The integer 4 divides the integer 32 because 32 = 8 × 4. The integer 4 divides the integer 32 because 32 = 8 × 4. We show this asWe show this as

b. The number 8 does not divide the number 42 because b. The number 8 does not divide the number 42 because 42 = 5 × 8 + 2. There is a remainder, the number 2, in the 42 = 5 × 8 + 2. There is a remainder, the number 2, in the

equation. We show this as equation. We show this as

Page 12: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.12

Properties

2.1.4 Continued

Property 1: if a|1, then a = ±1.

Property 2: if a|b and b|a, then a = ±b.

Property 3: if a|b and b|c, then a|c.

Property 4: if a|b and a|c, then a|(m × b + n × c), where m and n are arbitrary integers

Page 13: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.13

Example 2.5

2.1.4 Continued

Page 14: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.14

Example 2.6

2.1.4 Continued

Page 15: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.15

2.1.4 Continued

Fact 1: The integer 1 has only one divisor, itself.

Fact 2: Any positive integer has at least two divisors, 1 and itself (but it can have more).

Note

Page 16: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.16

2.1.4 ContinuedFigure 2.6 Common divisors of two integers

Page 17: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.17

Euclidean Algorithm

2.1.4 Continued

Fact 1: gcd (a, 0) = aFact 2: gcd (a, b) = gcd (b, r), where r is the remainder of dividing a by b

The greatest common divisor of two positive integers is the largest integer that can divide both integers.

Greatest Common Divisor

Note

Note

Page 18: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.18

2.1.4 ContinuedFigure 2.7 Euclidean Algorithm

When gcd (a, b) = 1, we say that a and b are relatively prime.

Note

Page 19: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.19

2.1.4 Continued

When gcd (a, b) = 1, we say that a and b are relatively prime.

Note

Page 20: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.20

Example 2.7

2.1.4 Continued

Find the greatest common divisor of 2740 and 1760.Find the greatest common divisor of 2740 and 1760.

We have gcd (2740, 1760) = 20.We have gcd (2740, 1760) = 20.

SolutionSolution

Page 21: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.21

Example 2.8

2.1.4 Continued

Find the greatest common divisor of 25 and 60.Find the greatest common divisor of 25 and 60.

We have gcd (25, 65) = 5.We have gcd (25, 65) = 5.SolutionSolution

Page 22: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.22

Extended Euclidean Algorithm

2.1.4 Continued

Given two integers Given two integers aa and and bb, we often need to find other two , we often need to find other two integers, integers, ss and and tt, such that, such that

The extended Euclidean algorithm can calculate the gcd (The extended Euclidean algorithm can calculate the gcd (aa, , bb) ) and at the same time calculate the value of and at the same time calculate the value of ss and and tt..

Page 23: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.23

2.1.4 ContinuedFigure 2.8.a Extended Euclidean algorithm, part a

Page 24: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.24

2.1.4 ContinuedFigure 2.8.b Extended Euclidean algorithm, part b

Page 25: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.25

Example 2.9

2.1.4 Continued

Given Given aa = 161 and = 161 and bb = 28, find gcd ( = 28, find gcd (aa, , bb) and the values of ) and the values of ss and and tt..

We get gcd (161, 28) = 7, We get gcd (161, 28) = 7, ss = −1 and = −1 and tt = 6. = 6.SolutionSolution

Page 26: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.26

Example 2.10

2.1.4 Continued

Given Given aa = 17 and = 17 and bb = 0, find gcd ( = 0, find gcd (aa, , bb) and the values of ) and the values of ss and and tt..

We get gcd (17, 0) = 17, We get gcd (17, 0) = 17, ss = 1, and = 1, and tt = 0 = 0..

SolutionSolution

Page 27: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.27

Example 2.11

2.1.4 Continued

Given Given aa = 0 and = 0 and bb = 45, find gcd ( = 45, find gcd (aa, , bb) and the values of ) and the values of ss and and tt..

We get gcd (0, 45) = 45, We get gcd (0, 45) = 45, ss = 0, and = 0, and tt = 1. = 1.SolutionSolution

Page 28: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.28

2-2 MODULAR ARITHMETIC2-2 MODULAR ARITHMETIC

The division relationship (a = q × n + r) discussed in The division relationship (a = q × n + r) discussed in the previous section has two inputs (a and n) and two the previous section has two inputs (a and n) and two outputs (q and r). In modular arithmetic, we are outputs (q and r). In modular arithmetic, we are interested in only one of the outputs, the interested in only one of the outputs, the remainder rremainder r. .

Page 29: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.29

The modulo operator is shown as mod. The second input (n) is called the modulus. The output r is called the residue.

2.2.1 Modulo Operator

Figure 2.9 Division algorithm and modulo operator

Page 30: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.30

Example 2.14

2.1.4 Continued

Find the result of the following operations:Find the result of the following operations:a.a. 27 mod 5 27 mod 5 b.b. 36 mod 12 36 mod 12c.c. −18 mod 14 −18 mod 14 d.d. −7 mod 10 −7 mod 10

a.a. Dividing 27 by 5 results in Dividing 27 by 5 results in rr = 2 = 2

b.b. Dividing 36 by 12 results in Dividing 36 by 12 results in rr = 0. = 0.

c. Dividing −18 by 14 results in c. Dividing −18 by 14 results in rr = −4. After adding the = −4. After adding the modulus modulus rr = 10 = 10

d. Dividing −7 by 10 results in r = −7. After adding the d. Dividing −7 by 10 results in r = −7. After adding the modulus to −7, r = 3. modulus to −7, r = 3.

SolutionSolution

Page 31: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.31

The result of the modulo operation with modulus n is always an integer between 0 and n-1. The modulo operation creates a set, which in modular arithmetic is referred to as the set of least residues modulo n, or Zn.

2.2.2 Set of Residues

Figure 2.10 Some Zn sets

Page 32: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.32

In cryptography, we often use the concept of congruence instead of equality. To show that two integers are congruent, we use the congruence operator ( ≡ ). We add the phrase (mod n) to the right side of the congruence to define the value of modulus that makes the relationship valid. For example, we write:

2.2.3 Congruence

Page 33: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.33

2.2.3 ContinuedFigure 2.11 Concept of congruence

Page 34: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.34

Example 2.15

2.2.3 Continued

We use modular arithmetic in our daily life; for example, we We use modular arithmetic in our daily life; for example, we use a clock to measure time. Our clock system uses modulo 12 use a clock to measure time. Our clock system uses modulo 12 arithmetic. However, instead of a 0 we use the number 12. arithmetic. However, instead of a 0 we use the number 12.

Page 35: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.35

The three binary operations that we discussed for the set Z can also be defined for the set Zn. The result may need to be mapped to Zn using the mod operator.

2.2.4 Operation in Zn

Figure 2.13 Binary operations in Zn

Page 36: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.36

Example 2.16

2.2.4 Continued

Perform the following operations (the inputs come from Zn):Perform the following operations (the inputs come from Zn):a. Add 7 to 14 in Z15.a. Add 7 to 14 in Z15.b. Subtract 11 from 7 in Z13.b. Subtract 11 from 7 in Z13.c. Multiply 11 by 7 in Z20.c. Multiply 11 by 7 in Z20.

SolutionSolution

Page 37: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.37

Example 2.17

2.2.4 Continued

Perform the following operations (the inputs come from Perform the following operations (the inputs come from either Z or Zeither Z or Znn):):a. Add 17 to 27 in Za. Add 17 to 27 in Z1414..b. Subtract 43 from 12 in Zb. Subtract 43 from 12 in Z1313..c. Multiply 123 by −10 in Zc. Multiply 123 by −10 in Z1919..

SolutionSolution

Page 38: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.38

Properties

2.2.4 Continued

Page 39: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.39

2.2.4 ContinuedFigure 2.14 Properties of mode operator

Page 40: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.40

Example 2.18

2.2.4 Continued

The following shows the application of the above properties:The following shows the application of the above properties:

1. (1,723,345 + 2,124,945) mod 11 = (8 + 9) mod 11 = 61. (1,723,345 + 2,124,945) mod 11 = (8 + 9) mod 11 = 6

2. (1,723,345 − 2,124,945) mod 16 = (8 − 9) mod 11 = 102. (1,723,345 − 2,124,945) mod 16 = (8 − 9) mod 11 = 10

3. (1,723,345 × 2,124,945) mod 16 = (8 × 9) mod 11 = 63. (1,723,345 × 2,124,945) mod 16 = (8 × 9) mod 11 = 6

Page 41: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.41

Example 2.19

2.2.4 Continued

In arithmetic, we often need to find the remainder of powers In arithmetic, we often need to find the remainder of powers of 10 when divided by an integer. of 10 when divided by an integer.

Page 42: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.42

Example 2.20

2.2.4 Continued

We have been told in arithmetic that the remainder of an We have been told in arithmetic that the remainder of an integer divided by 3 is the same as the remainder of the sum integer divided by 3 is the same as the remainder of the sum of its decimal digits. We write an integer as the sum of its of its decimal digits. We write an integer as the sum of its digits multiplied by the powers of 10.digits multiplied by the powers of 10.

Page 43: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.43

2.2.5 Inverses

When we are working in modular arithmetic, we often need When we are working in modular arithmetic, we often need to find the inverse of a number relative to an operation. We to find the inverse of a number relative to an operation. We are normally looking for an additive inverse (relative to an are normally looking for an additive inverse (relative to an addition operation) or a multiplicative inverse (relative to a addition operation) or a multiplicative inverse (relative to a multiplication operation).multiplication operation).

Page 44: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.44

2.2.5 Continue

In ZIn Znn, two numbers , two numbers aa and and bb are additive inverses of each are additive inverses of each other ifother if

Additive Inverse

In modular arithmetic, each integer has an additive inverse. The sum of an integer and its additive inverse is

congruent to 0 modulo n.

Note

Page 45: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.45

Example 2.21

2.2.5 Continued

Find all additive inverse pairs in Z10.Find all additive inverse pairs in Z10.

SolutionSolution

The six pairs of additive inverses are (0, 0), (1, 9), (2, 8), (3, 7), The six pairs of additive inverses are (0, 0), (1, 9), (2, 8), (3, 7), (4, 6), and (5, 5). (4, 6), and (5, 5).

Page 46: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.46

2.2.5 Continue

In ZIn Znn, two numbers , two numbers aa and and bb are the multiplicative inverse of are the multiplicative inverse of each other ifeach other if

Multiplicative Inverse

In modular arithmetic, an integer may or may not have a multiplicative inverse.

When it does, the product of the integer and its multiplicative inverse is

congruent to 1 modulo n.

Note

Page 47: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.47

Example 2.22

2.2.5 Continued

Find the multiplicative inverse of 8 in ZFind the multiplicative inverse of 8 in Z1010..

SolutionSolutionThere is no multiplicative inverse because gcd (10, 8) = 2 ≠ 1. There is no multiplicative inverse because gcd (10, 8) = 2 ≠ 1. In other words, we cannot find any number between 0 and 9 In other words, we cannot find any number between 0 and 9 such that when multiplied by 8, the result is congruent to 1.such that when multiplied by 8, the result is congruent to 1.

Example 2.23

Find all multiplicative inverses in ZFind all multiplicative inverses in Z1010..

SolutionSolutionThere are only three pairs: (1, 1), (3, 7) and (9, 9). The There are only three pairs: (1, 1), (3, 7) and (9, 9). The numbers 0, 2, 4, 5, 6, and 8 do not have a multiplicative numbers 0, 2, 4, 5, 6, and 8 do not have a multiplicative inverse. inverse.

Page 48: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.48

Example 2.24

2.2.5 Continued

Find all multiplicative inverse pairs in ZFind all multiplicative inverse pairs in Z1111..

SolutionSolution

We have seven pairs: (1, 1), (2, 6), (3, 4), (5, 9), (7, 8), (9, 9), We have seven pairs: (1, 1), (2, 6), (3, 4), (5, 9), (7, 8), (9, 9), and (10, 10). and (10, 10).

Page 49: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.49

2.2.5 Continued

The extended Euclidean algorithm finds the multiplicative inverses of b in Zn

when n and b are given and gcd (n, b) = 1.

The multiplicative inverse of b is the value of t after being mapped to Zn.

Note

Page 50: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.50

2.2.5 ContinuedFigure 2.15 Using extended Euclidean algorithm to find multiplicative inverse

Page 51: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.51

Example 2.25

2.2.5 Continued

Find the multiplicative inverse of 11 in ZFind the multiplicative inverse of 11 in Z2626..

SolutionSolution

The gcd (26, 11) is 1; the inverse of 11 is The gcd (26, 11) is 1; the inverse of 11 is 7 or 19.7 or 19.

Page 52: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.52

Example 2.26

2.2.5 Continued

Find the multiplicative inverse of 23 in ZFind the multiplicative inverse of 23 in Z100100..

SolutionSolution

The gcd (100, 23) is 1; the inverse of 23 is The gcd (100, 23) is 1; the inverse of 23 is 13 or 87.13 or 87.

Page 53: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.53

Example 2.27

2.2.5 Continued

Find the inverse of 12 in ZFind the inverse of 12 in Z2626..

SolutionSolution

The gcd (26, 12) is 2; the inverse does not exist.The gcd (26, 12) is 2; the inverse does not exist.

Page 54: Chapter 2 Mathematics of Cryptography Part I: Modular Arithmetic

2.54

2.2.6 Addition and Multiplication Tables Figure 2.16 Addition and multiplication table for Z10