EuclideanandExtdndEuclodeanAlgo (1)
EuclideanandExtdndEuclodeanAlgo (1)
Mechanisms
Modular Arithmetic
Euclid’s Algorithm
Extended Euclid’s Algorithm
2
Modular Arithmetic
Modular arithmetic refers to perform all arithmetic operations using
the mod n operator.
Given any positive integer n and any non-negative integer a, if we
divide a by n, we get a= qn + r, where q= quotient r=remainder
a=11; n=7; 11=1 x 7 + 4; r=4, q=1
a= -11; n=7; -11=(-
11=(-2) x 7 + 3; r=3, q=-
q=-2
When a is divided by n, a mod n is defined to be the remainder r and
the integer n is called the modulus.
3
Modular Arithmetic Operation
4
Congruence
Two integers a and b are said to be congruent modulo n,
if (a mod n) = (b mod n). This is written as a≡ b (mod n)
(11 mod 4) ≡ (7 mod 4) 11 ≡ 7 (mod 4 )
(21 mod 10) ≡ (-9 mod 10) 21 ≡ - 9 (mod 10)
5
Arithmetic Modulo 8
a + b mod 8
Arithmetic Modulo 8
a x b mod 8
Arithmetic Modulo 8
• The additive inverse, opposite of a number a is the number that,
inverse or opposite,
when added to a, yields zero. The additive inverse of F is denoted −F
The multiplicative inverse or reciprocal for a number x, denoted by 1/x
or x−1, is a number which when multiplied by x yields the multiplicative
identity, 1
Greatest Common Divisor (GCD)
q = r1/r2 r1 r2 r = r1 – qxr2
5 120 23 5
4 23 5 3
1 5 3 2
1 3 2 1
2 2 1 0
1 0
GCD(a,b)=GCD(2740,1760)=20
The Extended Euclidean Algorithm
The Extended Euclidean Algorithm can be used to find the
multiplicative inverse of a positive integer a mod n
Multiplicative Inverse
The multiplicative inverse of a is an element a-1 Є Zm, such
that aa-1≡ 1 (mod m)
5 120 23 5 1 0 1 0 1 -5
4 23 5 3 0 1 -4 1 -5 21
1 5 3 2 1 -4 5 -5 21 -26
1 3 2 1 -4 5 -9 21 -26 47
2 2 1 0 5 -9 23 -26 47 -120
1 0 -9 23 47 -120
When r2=0, gcd(120,23)= r1=1, s=s1 =-9, t=t1 =47 And a-1 =t=47 mod 120