Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module :MA3036NI Cryptography and Number Theory Lecture Week 7

Similar presentations


Presentation on theme: "Module :MA3036NI Cryptography and Number Theory Lecture Week 7"— Presentation transcript:

1 Module :MA3036NI Cryptography and Number Theory Lecture Week 7

2 Quotient remainder theorem, GCD and Euclid's algorithm
The quotient remainder theorem For any two integers a and b with b > 0, there are unique integers q and r such that a = qb + r with 0 ≤ r < b, then q is called the quotient and r is called the remainder when a is divided by b.

3 Greatest common divisor (GCD)
Definition A positive integer d is said to be the greatest common divisor of a and b (a, b not both zero) if and only if (i) d is a common divisor of a and b, i.e. d|a and d|b, (ii) any common divisor of a and b is a divisor of d, i.e. if x|a and x|b then x|d. We then write d = gcd(a, b).

4 Greatest common divisor (GCD)
Note (i) The gcd(a, b) is the largest positive integer that divides a and b. (ii) gcd(0, n) = |n| if n is not 0. (iii) If gcd(a, b) = 1 then a and b are said to be relatively prime or co prime. Example Find the answers to the following: (i) gcd(12, 18), (ii) gcd(-12, 18), (iii) gcd(35, 49), (iv) gcd(0, -5), (v) gcd(3, 4), (vi) gcd(3, 9), (vii) gcd(0, 5).

5 The Euclidean Algorithm
Euclid’s algorithm to find gcd(a, b) (1) Assume a ≥ b > 0 (else interchange a and b). (2) Write a = qb + r where 0 ≤ r < b. (3) IF r = 0 THEN b is the gcd(a, b). STOP ELSE replace (a, b) by (b, r) and continue with step (2).

6 The Euclidean Algorithm
Example Find gcd(1598, 282) using Euclid’s algorithm. Solution, a b r 1598 = 5 * 282 = 1 * 188 = 2 * Thus gcd(1598, 282) = 94.

7 The Euclidean Algorithm
Note For any two positive integers a and b, gcd(a, b) exists, (ii) there exist integers m, n € Z such that gcd(a,b) = ma + nb.

8 The Euclidean Algorithm
Example (i) Find the gcd(2403, 663) using Euclid’s algorithm. (ii) Write gcd(2403, 663) in the form m × n × 663 where m, n € Z.

9 linear Diophantine equation
A linear Diophantine equation of two variables is ax + by = c. Particular solution: x0 = (c/d)m and y0 = (c/d)n General solutions: x = x0 + k (b / d) and y = y0 − k(a / d) where k is an integer

10 Exercises….. Q.Find the particular and general solutions to the following Diophantine equations i) 24x + 36y = 54 ii) 10x + 25y =100 iii) 6x +13y = 20

11 Modular Arithmetic define modulo operator “a mod n” to be remainder when a is divided by n where integer n is called the modulus a & b are congruent if: a mod n = b mod n when divided by n, a & b have same remainder This is written as a ≡ b mod n e.g ≡ 34 mod 11 Given any positive integer n and any nonnegative integer a, if we divide a by n, we get an integer quotient q and an integer remainder r. In modular arithmetic we are only interested in the remainder (or residue) after division by some modulus, and results with the same remainder are regarded as equivalent. Two integers a and b are said to be congruent modulo n, if (a mod n) =(b mod n).

12 Modular Arithmetic

13 Modular Arithmetic Operations
[(a mod n) + (b mod n)] mod n = (a + b) mod n [(a mod n) – (b mod n)] mod n = (a – b) mod n [(a mod n) x (b mod n)] mod n = (a x b) mod n Verify the above properties using suitable examples . Modular arithmetic exhibits the properties shown, see text for details & proofs. Here are examples of the three properties: Given 11 mod 8 = 3; 15 mod 8 = 7 [(11 mod 8) + (15 mod 8)] mod 8 = 10 mod 8 = 2 ( ) mod 8 = 26 mod 8 = 2 [(11 mod 8) – (15 mod 8)] mod 8 = –4 mod 8 = 4 (11 – 15) mod 8 = –4 mod 8 = 4 [(11 mod 8) x (15 mod 8)] mod 8 = 21 mod 8 = 5 (11 x 15) mod 8 = 165 mod 8 = 5

14 Modular Arithmetic (cont’d)
Proof of Property 1: Define (a mod n) = ra and (b mod n) = rb. Then a = ra + jn and b = rb + kn for some integers j and k. Then, (a+b) mod n = (ra + jn + rb + kn) mod n = (ra + rb + (j + k)n) mod n = (ra + rb) mod n = [(a mod n) + (b mod n)] mod n. Prove Property 2 and 3 in similar manner

15 Modular Arithmetic (cont’d)
Exponentiation is performed by repeated multiplication, as in ordinary arithmetic. Thus the rules for ordinary arithmetic involving addition, subtraction and multiplication carry over into modular arithmetic . To find 11⁷ mod 13, we can proceed as follows: 11² = 121≡ 4 (mod 13) 11⁴= (11²)²≡ 4² ≡ 3 (mod 13) 11⁷≡11*4 *3 ≡132≡2 (mod 13) Find 12⁹ mod 13 .

16 Modulo 8 Addition Example
+ 1 2 3 4 5 6 7 Example showing addition in GF(8), from Stallings Table 4.2a. Table 4.2 provides an illustration of modular addition and multiplication modulo 8. Looking at addition, the results are straightforward and there is a regular pattern to the matrix. Both matrices are symmetric about the main diagonal, in conformance to the commutative property of addition and multiplication. As in ordinary addition, there is an additive inverse, or negative, to each integer in modular arithmetic. In this case, the negative of an integer x is the integer y such that (x + y) mod 8 = 0. To find the additive inverse of an integer in the left-hand column, scan across the corresponding row of the matrix to find the value 0; the integer at the top of that column is the additive inverse; thus (2 + 6) mod 8 = 0.

17 Modulo 8 Multiplication
1 2 3 4 5 6 7 Continuing the example showing multiplication in GF(8), from Stallings Table 4.2b. Both matrices are symmetric about the main diagonal, in conformance to the commutative property of addition and multiplication. Similarly, the entries in the multiplication table are straightforward. In ordinary arithmetic, there is a multiplicative inverse, or reciprocal, to each integer. In modular arithmetic mod 8, the multiplicative inverse of x is the integer y such that (x x y) mod 8 = 1 mod 8. Now, to find the multiplicative inverse of an integer from the multiplication table, scan across the matrix in the row for that integer to find the value 1; the integer at the top of that column is the multiplicative inverse; thus (3 x 3) mod 8 = 1. Note that not all integers mod 8 have a multiplicative inverse; more about that later.

18 Modular Arithmetic Properties
Let Zn = {0,1,2,…,(n-1)} be the set of residues modulo n. If we perform modular arithmetic within Zn, the properties shown in Table 4.3 hold for integers in Zn We show in the next section that this implies that Zn is a commutative ring with a multiplicative identity element. Note that unlike ordinary arithmetic, the following statement is true only with the attached condition: if (a x b) = (a x c) (mod n) then b = c (mod n) if a is relatively prime to n In general, an integer has a multiplicative inverse in Zn if that integer is relatively prime to n. Table 4.2 cin the text shows that the integers 1, 3, 5, and 7 have a multiplicative inverse in Z 8, but 2, 4, and 6 do not.

19 Additive Inverse In Zn, two numbers a and b are additive inverses of each other if In modular arithmetic, each integer has an additive inverse. The sum of an integer and its additive inverse is congruent to 0 modulo n.

20 Find all additive inverse pairs in Z10.
Solution The six pairs of additive inverses are (0, 0), (1, 9), (2, 8), (3, 7), (4, 6), and (5, 5).

21 Multiplicative Inverse
In Zn, two numbers a and b are the multiplicative inverse of each other if 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.

22 Find the multiplicative inverse of 8 in Z10.
Solution There is no multiplicative inverse because gcd (10, 8) = 2 ≠ 1. In other words, we cannot find any number between 0 and 9 such that when multiplied by 8, the result is congruent to 1. Find all multiplicative inverses in Z10. Solution There are only four pairs: (1, 1), (3, 7) , (7 , 3)and (9, 9). The numbers 0, 2, 4, 5, 6, and 8 do not have a multiplicative inverse.

23 Find all multiplicative inverse pairs in Z11.
Solution We have seven pairs: (1, 1), (2, 6), (3, 4), (5, 9), (7, 8), (9, 9), and (10, 10).

24 Addition and Multiplication Tables Z10

25 Extended Euclidian algorithm to find Multiplicative inverse
If we perform modular arithmetic within Zn, the properties shown in Table 4.3 hold for integers in Zn We show in the next section that this implies that Zn is a commutative ring with a multiplicative identity element. Note that unlike ordinary arithmetic, the following statement is true only with the attached condition: if (a x b) = (a x c) (mod n) then b = c (mod n) if a is relatively prime to n In general, an integer has a multiplicative inverse in Zn if that integer is relatively prime to n. Table 4.2 cin the text shows that the integers 1, 3, 5, and 7 have a multiplicative inverse in Z 8, but 2, 4, and 6 do not.

26 Fermat's Theorem Fermat’s theorem states that, ap-1 mod p = 1
where p is prime and gcd(a , p)=1 Proof : See section 8.2 from book

27 Euler's Theorem A generalisation of Fermat's Theorem, Which States that , aø(n)mod n = 1 where gcd(a , n)=1 Proof: See section 8.2 from book

28 Extended Euclidian Algorithm
Question: Using the Extended Euclidean Algorithm , find the multiplicative inverse of 1234 mod ( Note :d = 1234 f = 4321)


Download ppt "Module :MA3036NI Cryptography and Number Theory Lecture Week 7"

Similar presentations


Ads by Google