module :ma3036ni cryptography and number theory lecture week 7
TRANSCRIPT
Module :MA3036NICryptography and Number Theory
Lecture Week 7
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.
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).
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).
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).
The Euclidean Algorithm
Example Find gcd(1598, 282) using Euclid’s algorithm. Solution, a b r 1598 = 5 * 282 + 188 282 = 1 * 188 + 94 188 = 2 * 94 + 0 Thus gcd(1598, 282) = 94.
The Euclidean Algorithm
Note
For any two positive integers a and b, (i)gcd(a, b) exists, (ii) there exist integers m, n € Z such that gcd(a,b) = ma + nb.
The Euclidean Algorithm
Example
(i) Find the gcd(2403, 663) using Euclid’s algorithm.
(ii) Write gcd(2403, 663) in the form m × 2403 + n × 663 where m, n € Z.
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
Exercises…..
Q.Find the particular and general solutions to the Q.Find the particular and general solutions to the following following Diophantine equations equations i) 24x + 36y = 54 ii) 10x + 25y =100 iii) 6x +13y = 20i) 24x + 36y = 54 ii) 10x + 25y =100 iii) 6x +13y = 20
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.. 100 ≡ 34 mod 11
Modular Arithmetic
12
The Congruent modulo operator has the following properties:
1. a≡ b mod n if n|(a-b). 2. a≡ b mod n implies b≡ a mod n. 3. a≡ b mod n and b≡ c mod n imply a≡ c mod n.
23≡ 8 (mod 5) because 23-8=15=5× 3-11≡ 5 (mod 8) because -11-5=-16=8× (-2)81≡ 0 (mod 27) because 81-0=81=27× 3
Modular Arithmetic Operations
1.[(a mod n) + (b mod n)] mod n = (a + b) mod n
2.[(a mod n) – (b mod n)] mod n = (a – b) mod n
3.[(a mod n) x (b mod n)] mod n = (a x b) mod n
Verify the above properties using suitable examples .
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 .
Modulo 8 Addition Example
+ 0 1 2 3 4 5 6 7
0 0 1 2 3 4 5 6 7
1 1 2 3 4 5 6 7 0
2 2 3 4 5 6 7 0 1
3 3 4 5 6 7 0 1 2
4 4 5 6 7 0 1 2 3
5 5 6 7 0 1 2 3 4
6 6 7 0 1 2 3 4 5
7 7 0 1 2 3 4 5 6
Modulo 8 Multiplication
ₓ 0 1 2 3 4 5 6 7
0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7
2 0 2 4 6 0 2 4 6
3 0 3 6 1 4 7 2 5
4 0 4 0 4 0 4 0 4
5 0 5 2 7 4 1 6 3
6 0 6 4 2 0 6 4 2
7 0 7 6 5 4 3 2 1
Modular Arithmetic PropertiesLet Zn = {0,1,2,…,(n-1)} be the set of residues modulo
n.
In ZIn Znn, two numbers a and b are additive inverses of each other if, two numbers a and b are additive inverses of each other 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.
Find all additive inverse pairs in Z10Find all additive inverse pairs in Z10..
SolutionSolution
The six pairs of additive inverses are (0, 0), (1, 9), The six pairs of additive inverses are (0, 0), (1, 9), (2, 8), (3, 7), (4, 6), and (5, 5). (2, 8), (3, 7), (4, 6), and (5, 5).
In ZIn Znn, two numbers a and b are the multiplicative inverse of each , two numbers a and b are the multiplicative inverse of each other ifother 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.
Find the multiplicative inverse of 8 in ZFind the multiplicative inverse of 8 in Z1010..SolutionSolution
There is no multiplicative inverse because gcd (10, 8) = 2 ≠ 1. In There is no multiplicative inverse because gcd (10, 8) = 2 ≠ 1. In other words, we cannot find any number between 0 and 9 such other words, we cannot find any number between 0 and 9 such that when multiplied by 8, the result is congruent to 1.that when multiplied by 8, the result is congruent to 1.
Find all multiplicative inverses in ZFind all multiplicative inverses in Z1010..SolutionSolution
There are only four pairs: (1, 1), (3, 7) , (7 , 3)and (9, 9). The 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. numbers 0, 2, 4, 5, 6, and 8 do not have a multiplicative inverse.
Find all multiplicative inverse pairs in ZFind all multiplicative inverse pairs in Z1111..SolutionSolutionWe have seven pairs: (1, 1), (2, 6), (3, 4), (5, 9), (7, 8), (9, 9), and We have seven pairs: (1, 1), (2, 6), (3, 4), (5, 9), (7, 8), (9, 9), and (10, 10). (10, 10).
Addition and Multiplication Tables Z10
Extended Euclidian algorithm to find Multiplicative inverse
EXTENDED EUCLID(d,f)
1.(X1,X2,X3) ← (1,0,f);(Y1,Y2,Y3) ← (0,1,d)
2.if Y3=0 return X3=gcd(d,f); no inverse
3.if Y3=1 return Y3=gcd(d,f); Y2=d-1 mod f
4.Q=
3
3
YX
5.(T1,T2,T3) ← (X1-QY1,X2-QY2,X3-QY3)
6.(X1,X2,X3) ← (Y1,Y2,Y3)
7.(Y1,Y2,Y3) ← (T1,T2,T3)
8. goto 2
26
Fermat's TheoremFermat’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)=1Proof:See section 8.2 from book
28
Extended Euclidian Algorithm
Question:
Using the Extended Euclidean Algorithm , find the multiplicative inverse of 1234 mod 4321.
( Note :d = 1234 f = 4321)