SlideShare a Scribd company logo
Module 3:
Number-Theoretic Algorithms
1
2
Prime and composite numbers
 The first 20 primes, in order, are
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
71
 Example, 39 is composite because 3 | 39
3
Common divisors and greatest common divisors
 If d is a divisor of a and d is also a divisor of b, then d is a common divisor of a
and b.
 For example:
 The divisors of 30 are 1, 2, 3, 5, 6, 10, 15, and 30,
 The divisors of 24 are 1, 2, 3, 6, 8, 12, and 24
 and so the common divisors of 24 and 30 are 1, 2, 3, and 6.
 The greatest common divisor of two integers a and b, not both zero,
is the largest of the common divisors of a and b.
 For example: gcd(24,30)=6
4
 Greatest common divisor
 Euclid’s algorithm used to compute greatest
common divisors.
5
Example of the running of EUCLID, consider the computation
of gcd (30,21)
6
EXAMPLE
Calculate: gcd(22, 60) = gcd(60,22)
60 = 2 x 22 + 16 = Euclid(22,16)
22 = 1 x 16 + 6 = Euclid(16,6)
16 = 2 x 6 + 4 = Euclid(6,4)
6 = 1 x 4 + 2 = Euclid(4,2)
4 = 2 x 2 + 0 = Euclid(2,0)
= 2.
7
The running time of Euclid’s algorithm
 The overall running time of EUCLID is proportional to the number of recursive
calls it makes.
 The number of recursive calls in EUCLID is O(log b)
8
The extended form of Euclid’s algorithm
 The procedure EXTENDED_EUCLID takes as input a pair of nonnegative integers
and returns a triple of the form (d,x,y).
9
Figure : illustrates how EXTENDED-EUCLID computes gcd(99,78)
10
a b [a/b] d x y
99 78
Example: gcd(99,78)
11
a b [a/b] d x y
99 78 1
gcd(99,78)
12
a b [a/b] d x y
99 78 1
78 21
Remainder
Example: gcd(99,78)
13
a b [a/b] d x y
99 78 1
78 21 3
Example: gcd(99,78)
14
a b [a/b] d x y
99 78 1
78 21 3
21 15
Remainder
Example: gcd(99,78)
15
a b [a/b] d x y
99 78 1
78 21 3
21 15 1
15 6 2
6 3 2
3 0 -
Example: gcd(99,78)
16
a b [a/b] d x y
99 78 1
78 21 3
21 15 1
15 6 2
6 3 2
3 0 - 3 1 0
Example: gcd(99,78)
When b=0 , then d=b and initialize x=1
and y=0
17
a b [a/b] d x y
99 78 1 3
78 21 3 3
21 15 1 3
15 6 2 3
6 3 2 3 0 1
3 0 - 3 1 0
Example: gcd(99,78)
For every step, calculate x and y
Step 1: New x value = previous y value
x=0
New y value = previous x value – ([a/b] * (previous y value)
y= 1- (2*0) = 1
18
a b [a/b] d x y
99 78 1
78 21 3
21 15 1
15 6 2 3 1 -2
6 3 2 3 0 1
3 0 - 3 1 0
For every step, calculate x and y
Step 2: New x value = previous y value
x=1
New y value = previous x value – ([a/b] * (previous y value)
y= 0- (2*1) = -2
Example: gcd(99,78)
19
a b [a/b] d x y
99 78 1
78 21 3
21 15 1 3 -2 3
15 6 2 3 1 -2
6 3 2 3 0 1
3 0 - 3 1 0
For every step, calculate x and y
Step 3: New x value = previous y value
x= -2
New y value = previous x value – ([a/b] * (previous y value)
y= 1- (1*-2) = 3
Example: gcd(99,78)
20
a b [a/b] d x y
99 78 1 3 -11 14
78 21 3 3 3 -11
21 15 1 3 -2 3
15 6 2 3 1 -2
6 3 2 3 0 1
3 0 - 3 1 0
Example: gcd(99,78)
21
 Since the number of recursive calls made in EUCLID is equal to the number of
recursive calls made in EXTENDED-EUCLID, the running times of EUCLID
and EXTENDED-EUCLID are the same, to within a constant factor.
 That is, for a > b > 0, the number of recursive calls is O(log b).
 Example:
gcd(66, 24) = 6
gcd (899,493) =29
gcd (95,355) =5
22
Modular Arithmetic
23
1. Modular Arithmetic :
a) Group : A group (S,) is a set S together with
binary operation  defined on S for which
the following properties hold :
i) Closure : For all a, b  S, a  b  S.
ii) Identity : There exists an element e  S,
called the identity of the group, 
a  e = e  a = a for all a  S.
iii) Associativity : For all a, b, c  S, we have
(a  b)  c = a  (b  c)
iv) Inverse : For each a  S, there exists a
unique element b  S, called the
inverse of ‘a’, such that
(a  b) = (b  a) = e
24
The familiar group (Z,+) of the integers Z under the
operation of addition: 0 is the identity, and the inverse of a
is -a.
Abelian Group : A group (S,) is said to be ‘Abelian
Group’, if it satisfies the commutative property.
(a  b) = (b  a)
25
Finite Group : A group (S,) is said to be ‘Finite
Group’, if it satisfies the property.
|S| < 
Sub-Group : If (S,) is a group, and S’  S and
(S’,) is also a group, then (S’,) is a sub
group of (S’,)
26
The groups defined by modular addition and multiplication
For any positive integer n, let S be the complete set of
residues {0, 1, 2,…, n−1}.
Addition modulo n on S is defined as follows.
For a and b in S, take the usual sum of a and b as
integers, and let r be the element of S to which the result
is congruent (modulo n); the sum a+b (mod n) is equal
to r.
(A + B) mod C = (A mod C + B mod C) mod C
27
28
The groups defined by modular addition and multiplication
For example, addition modulo 5 is given by the following
table: Finite group (Z6,+6)
Additive group modulo n
29
The groups defined by modular addition and multiplication
Multiplication modulo n is defined by taking ab (mod n)
to be equal to s, where s is the element of S to which the
usual product of a and b is congruent (modulo n).
(A * B) mod C = (A mod C * B mod C) mod C
30
The groups defined by modular addition and multiplication
For example, Multiplication modulo 15 is given by the
following table: Finite group (Z15,*15)
Multiplicative group modulo n
31
Solving modular linear equations
32
a x ≡ b (mod n)
where a > 0 and n > 0.
We assume that a, b, and n are given, and we wish to find all values of x,
modulo n.
33
34
Example : a= 14 b= 30 and n=100
Step1: gcd(14 , 100) = (a, n)
a b [a/b] d x y
14 100
100 14 7 2 1 -7
14 2 7 2 0 1
2 0 - 2 1 0
Solution of Extended Euclid Algorithm
d= 2
x= 1
y= -7
35
Step 2:
If d |b
if 2 | 30 , yes it divides
Then
x0 = -7 ( 30/2) mod 100 = 95
36
Step 3:
i=0
95 + 0 (100/2) mod 100 = 95
i=1
95 + 1 (100/2) mod 100 = 45
The loop on lines 4-5 prints the two solutions 95
and 45.
37
Assignment:
1. 35 x ≡ 10 (mod 50)
Sol: x1 = 16, x2 = 26, x3 = 36, x4 = 46 x5=6
2. 56x ≡ 1 mod 93
Sol: x=5
3. 5x ≡ 12 mod 19
Sol: x=48 x=12
4. 15x ≡ 12 mod 57
Sol: x ≡ 16, 35 or 54 mod 57.
38
The Chinese Remainder Theorem
39
 Around A.D. 100, the Chinese mathematician Sun-Ts˘u solved the
problem of finding those integers x that leave remainders 2, 3, and 2
when divided by 3, 5, and 7 respectively.
 One such solution is x =23
 The “Chinese remainder theorem” provides a correspondence between a
system of equations modulo a set of pairwise relatively prime moduli (for
example, 3, 5, and 7) and an equation modulo their product (for example,
105).
40
1. x ≡ 2 (mod 5) x ≡ 3 (mod 13)
Standard Equation : x ≡ a (mod n)
Solution:
a1= 2 a1 , a2 be integers
a2= 3
n1= 5 n= n1,n2 …… nk, where the ni are pairwise relatively prime
n2= 13
n = n1* n2 = 13*5 = 65
m1= n / n1 =13 moduli (m)
m2= n / n2 = 5
Calculate : ci = mi (mi
-1 mod ni)
41
1. x ≡ 2 (mod 5) x ≡ 3 (mod 13)
Standard Equation : x ≡ a (mod n)
Solution:
a1=2 a2= 3 n1= 5 n2= 13 n = 65 m1=13 m2= 5
Calculate : ci = mi (mi
-1 mod ni)
c1 = m1 (m1
-1 mod n1)
= 13 (13-1 mod 5) = 13 (2 mod 5) = 26
c2 = m2 (m2
-1 mod n2) = 5 (5-1 mod 13) = 5 (8 mod 13) = 40
x= (c1 *a1 + c2 *a2 ) mod n
= (26* 2 + 40 * 3 ) mod 65
= (52 +120) mod 65
= 42 (mod 65)
= 42
42
1. 13-1 (mod 5) = 13 * 0 ≡ 1 (mod 5) WRONG
13 * 1 ≡ 1 (mod 5) WRONG
13 * 2 ≡ 1 (mod 5) RIGHT
The modular inverse of 13 (mod 5) is 13-1 is 2
A x ≡ 1 (mod C)
The modular inverse of A (mod C) is A-1
2. 5 -1 (mod 13) = 5 * 0 ≡ 1 (mod 13) WRONG
5 * 1 ≡ 1 (mod 13) WRONG
5 * 2 ≡ 1 (mod 13) WRONG
5 * 3 ≡ 1 (mod 13) WRONG
5 * 4 ≡ 1 (mod 13) WRONG
5 * 5 ≡ 1 (mod 13) WRONG
5 * 6≡ 1 (mod 13) WRONG
5 * 7 ≡ 1 (mod 13) WRONG
5 * 8 ≡ 1 (mod 13) RIGHT
43
Find all solutions to the equations
1. x ≡ 2 (mod 5) x ≡ 3 (mod 13)
2. x ≡ 4 (mod 5) x ≡ 5 (mod 11)
3. x ≡ 6 (mod 11) x ≡ 13 (mod 16)
Solu:51669
4. x ≡ 9 (mod 21) x ≡ 19 (mod 25)
Solu:51669
5. x ≡ 1 (mod 5) x ≡ 2 (mod 7)
Solu:1731
6. x ≡ 3 (mod 9) x ≡ 4 (mod 11)
Solu: 1731
44
Powers of an Element
45
Consider the sequence of powers of ‘a’, modulo n
where a ∊ Zn
*. For example,
i 0 1 2 3 4 5 6 7 8 9
3i mod 7 1 3 2 6 4 5 1 3 2 6
i 0 1 2 3 4 5 6 7 8 9
2i mod 7 1 2 4 1 2 4 1 2 4 1
Now, < 2 > = {1, 2, 4} in Z7
*
< 3 > = {1, 3, 2, 6, 4, 5} in Z7
*
Here, ord7 (2) = 3 & ord7 (3) = 6
Powers of an Element :
46
Compute : ab (mod n)
Example: 7560 (mod 561)
Is it possible using Calculator ?
If yes, How much time?
So, Use MODULAR-EXPONENTIATION algorithm
47
MODULAR-EXPONENTIATION (a, b, n)
1. c = 0
2. d = 1
3. Let (bk , bk-1 , …..,b1 , b0 )
4. for i = k downto 0
5. c = 2c
6. d = (d.d) mod n
7. if bi = = 1
8. c = c + 1
9. d = (d.a) mod n
10. return d
48
Example: 7560 (mod 561)
a=7 b= 560 n=561
Step 1: The binary representation of b =560 is 1000110000
k=10 (count of 1’s and 0’s)
Step 2: c=0 d=1
for ( i = 10 downto 0 )
i=9
c= 2.c = 2.0 =0
d= (d*d) mod n = 1*1 mod 561
= 1
if b9 is 1
update c and d
c= 0+1 =1
d= 1* 7 mod 561 = 7 Result of this step: c=1 d=7
49
i=8
c= 2.c = 2.1 =2
d= (d*d) mod n = 7*7 mod 561
= 49
if b8 is not 1
So don’t update c and d
Result of this step: c=2 d=49
560 = 1000110000
50
i=7
c= 2.c = 2.2 =4
d= (d*d) mod n = 49*49 mod 561
= 157
if b7 is not 1
So don’t update c and d
Result of this step: c=4 d=157
560 = 1000110000
51
Final result is 7560 (mod 561) = 1
52
The RSA (Rivest–Shamir–Adleman)
public-key cryptosystem
53
In RSA Cryptosystem, the public and private keys are generated
as follows :
a) Select at random two large prime numbers
p and q such that p ≠ q.
b) Compute n = p*q
n is used as the modulus for both the public and private keys. Its length, usually
expressed in bits, is the key length.
54
c) Select a small odd integer ‘e’ that is relatively prime to
ø(n)= (p-1 * q-1) (public exponent)
d) Compute the integer ‘d’ (private exponent) from e, p and q
such that d * e ≡ 1 mod ø(n)
55
e) Publish P = (e,n) RSA Public Key
Keep Secret S = (d,n) RSA Secret
Key
Here, e = ENCRYPT(m) = me mod n
d = DECRYPT(c) = cd mod n
56
Apply RSA algorithm for the following.
p = 11 q = 29 e = 3
Encryption: Here n = pq = 319
(n) = p-1 * q-1 = 10 * 28 = 280
and d * e ≡ 1 mod 280
So, d = 187
Example:
Consider an RSA key set with p = 11, q = 29, n = 319, and e = 3.
What value of d should be used in the secret key?
What is the encryption of the message M =100?
57
Hence, (e, n) = (3, 319) is the public key and (d, n) = (187, 319) is the
private key.
For M = 100,
the cipher text is
1003 mod 319 = 254.
Here, e = ENCRYPT(m) = me mod n
d = DECRYPT(c) = cd mod n
Decryption:
the Plain text is
254187 mod 319 = 100.
58
Problems:
Sl No. Message P Q E Cipher Plain
Text
1. 7 11 3 ? ? ?
2. 88 17 11 ? ? ?
3. 513 137 131 ? ? ?
4. 123 61 53 ? ? ?
5. 148 23 37 ? ? ?
6. 42 13 19 ? ? ?
59
Problem with solution:
Sl No. Message P Q E Cipher Plain
Text
1. 7 11 3 3 13 7
2. 88 17 11 7 11 88
3. 513 137 131 3 8363 513
4. 123 61 53 17 855 123
5. 148 23 37 5 111 148
6. 42 13 19 7 120 42
60
Primality Testing
61
Primality Testing :
Methods for primality testing
1. Pseudoprimality testing
2. The Miller-Rabin randomized primality test
The problem of finding large primes.
62
Pseudoprimality testing
This procedure can make errors, but only of one type. That is, if it says
that n is composite, then it is always correct.
If it says that n is prime, however, then it makes an error only on
specific cases.
The first four such values are 341, 561, 645, and 1105. <10000
63
64
The Miller-Rabin randomized primality test
65
a) Carmichael number
A Carmichael number is a composite positive integer
which satisfies the following formula.
bn-1 ≡ 1 ( mod n)
for all integers ‘b’ which are relatively
prime to ‘n’.
The first Carmichael Number is : 561
66
MILLER-RABIN (n,s)
for j = 1 to s
a = RANDOM(1, n-1)
if WITNESS (a,n)
return COMPOSITE
return PRIME
 The Procedure MILLER-RABIN is a probabilistic search for a
proof that n is composite.
 In the following procedure, ‘s’ is the number of times the value
of ‘a’ is to be chosen at random.
67
WITNESS(a,n)
1. Let t and u be such that t ≥ 1.
u is odd, such that n-1 = 2t u
2. x0 = MODULAR-EXPONENTIATION(a,u,n)
3. for i = 1 to t
4. xi = x2
i-1 mod n
5. if ( xi = = 1) and ( xi-1 ≠ 1) and ( xi-1 ≠ n-1)
6. return TRUE
7. if xt ≠ 1
8. return TRUE
9. return FALSE
68
Example: Let ‘n’ be a carmichael number. n = 561
So, here n – 1 = 560
If n – 1 is written in the form of n-1 = 2t u, then
t = 4 and u = 35
Let the value of ‘a’ is chosen from the
algorithm as : 7
From the WITNESS algorithm,
find the value of x0.
Here, call the
MODULAR_EXPONENTIATION(a,u,n)
where a = 7 & u = 35 & n = 561
69
Here, d = ac mod n (c = b = u)
From above, the value of ‘d’ returned is : 241
Here, x0 ≡ 735 ≡ 241 (mod 561).
i init 5 4 3 2 1 0
bi -- 1 0 0 0 1 1
c 0 1 2 4 8 17 35
d 1 7 49 157 526 160 241
70
Here, d = ac mod n (c = b = u)
From above, the value of ‘d’ returned is : 241
1. Here, x0 ≡ 735 ≡ 241 (mod 561).
Note : Further we can have
2. 770 ≡ 298 (mod 561) = x1
3. 7140 ≡ 166 (mod 561) = x2
4. 7280 ≡ 67 (mod 561) = x3
5. 7560 ≡ 1 (mod 561) = x4
71
So, the sequence is : (241, 298, 166, 67, 1)
Thus, WITNESS discovers 1 in the last squaring
step, since a560 ≡ 1 (mod n)
Therefore, a = 7 is the witness to the compo-
siteness of ‘n’.
WITNESS(7,N) returns TRUE.
MILLER-RABIN returns COMPOSITE
Note : 561 = 3 . 11 . 17
72
Error rate of the Miller-Rabin primality test is very
less compared to Pseudoprimality testing
73
Integer factorization
74
Integer Factorization :
This is the process of integer factorization into a
product of primes.
Pollard’s rho heuristic :
This heuristic here helps in finding the product
of primes for the given integer.
POLLARD-RHO(n)
1. i = 1
2. x1 = RANDOM(0, n-1)
3. y = x1
4. k = 2
75
5. While TRUE
6. i = i + 1
7. xi = (x2
i-1 - 1 ) mod n
8. d = gcd(y – xi , n)
9. if ( d  1) and (d  n)
10. print d
11. if ( i = = k)
12. y = xi
13. k = 2k
Note : The above algorithm generates a set of factors
which are primes for the given integer.
76
Example: Pollard’s Rho Heuristic
Let n = 1387
So, Initialization :
i = 1 x1 = 2 y = 2 k = 2
WHILE : STEP-1 :
i= 2
xi = (x2
i-1 - 1 ) mod n  x2 = 3
d = gcd(y – xi , n)  d = 1
if [ (d  1) and ( d  n) ] FALSE
if ( i = =k) TRUE
y = 3 k = 4
77
STEP-2 : i= 3
xi = (x2
i-1 - 1 ) mod n  x3 = 8
d = gcd(y – xi , n)  d = 1
if [ (d  1) and ( d  n) ] FALSE
if ( i = =k) FALSE
STEP-3 : i= 4
xi = (x2
i-1 - 1 ) mod n  x4 = 63
d = gcd(y – xi , n)  d = 1
if [ (d  1) and ( d  n) ] FALSE
if ( i = =k) TRUE y = 63 k = 8
78
STEP-4 : i= 5
xi = (x2
i-1 - 1 ) mod n  x5 = 1194
d = gcd(y – xi , n)  d = 1
if [ (d  1) and ( d  n) ] FALSE
if ( i = = k) FALSE
STEP-5 : i = 6
xi = (x2
i-1 - 1 ) mod n  x6 = 1186
d = gcd(y – xi , n)  d = 1
if [ (d  1) and ( d  n) ] FALSE
if ( i = = k) FALSE
79
STEP-6 : i = 7
xi = (x2
i-1 - 1 ) mod n  x7 = 177
d = gcd(y – xi , n)  d = 19
if [ (d  1) and ( d  n) ] TRUE
 Print d = 19
if ( i = = k) FALSE
If the process is continued like this, we get another
factor : 73
The relation among the Xi values are shown in the
next slide :
80
310
996
396
814
84
x7 177
x6 1186 120
x5 1194 339 529
x4 63 595 1053
x3 8
x2 3
x1 2

More Related Content

What's hot

Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
Dr. C.V. Suresh Babu
 
AI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemAI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction Problem
Mohammad Imam Hossain
 
Informed search
Informed searchInformed search
Informed search
Amit Kumar Rathi
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysis
Iffat Anjum
 
Error detection & correction codes
Error detection & correction codesError detection & correction codes
Error detection & correction codes
Revathi Subramaniam
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structure
Vrushali Dhanokar
 
Air Cargo transport
 Air Cargo transport Air Cargo transport
Air Cargo transport
Faimin Khan
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
InteX Research Lab
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithmfaisal2204
 
Shortest path algorithm
Shortest  path algorithmShortest  path algorithm
Shortest path algorithm
Subrata Kumer Paul
 
First order predicate logic (fopl)
First order predicate logic (fopl)First order predicate logic (fopl)
First order predicate logic (fopl)
chauhankapil
 
Eucledian algorithm for gcd of integers and polynomials
Eucledian algorithm for gcd of integers and polynomialsEucledian algorithm for gcd of integers and polynomials
Eucledian algorithm for gcd of integers and polynomials
SWAMY J S
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Dr Shashikant Athawale
 
Fuzzy arithmetic
Fuzzy arithmeticFuzzy arithmetic
Fuzzy arithmetic
Mohit Chimankar
 
Adversarial search
Adversarial searchAdversarial search
Adversarial searchNilu Desai
 
Ford fulkerson
Ford fulkersonFord fulkerson
Ford fulkerson
bat coder
 
Virtual Private Networks (VPN) ppt
Virtual Private Networks (VPN) pptVirtual Private Networks (VPN) ppt
Virtual Private Networks (VPN) ppt
OECLIB Odisha Electronics Control Library
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AI
Megha Sharma
 

What's hot (20)

Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
AI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemAI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction Problem
 
Informed search
Informed searchInformed search
Informed search
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysis
 
Error detection & correction codes
Error detection & correction codesError detection & correction codes
Error detection & correction codes
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structure
 
Network flow problems
Network flow problemsNetwork flow problems
Network flow problems
 
Air Cargo transport
 Air Cargo transport Air Cargo transport
Air Cargo transport
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithm
 
Shortest path algorithm
Shortest  path algorithmShortest  path algorithm
Shortest path algorithm
 
First order predicate logic (fopl)
First order predicate logic (fopl)First order predicate logic (fopl)
First order predicate logic (fopl)
 
Eucledian algorithm for gcd of integers and polynomials
Eucledian algorithm for gcd of integers and polynomialsEucledian algorithm for gcd of integers and polynomials
Eucledian algorithm for gcd of integers and polynomials
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Fuzzy arithmetic
Fuzzy arithmeticFuzzy arithmetic
Fuzzy arithmetic
 
Adversarial search
Adversarial searchAdversarial search
Adversarial search
 
Ford fulkerson
Ford fulkersonFord fulkerson
Ford fulkerson
 
Lecture7
Lecture7Lecture7
Lecture7
 
Virtual Private Networks (VPN) ppt
Virtual Private Networks (VPN) pptVirtual Private Networks (VPN) ppt
Virtual Private Networks (VPN) ppt
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AI
 

Similar to ADVANCED ALGORITHMS-UNIT-3-Final.ppt

Modular arithmetic
Modular arithmeticModular arithmetic
Modular arithmetic
Janani S
 
Number theory
Number theoryNumber theory
Number theory
dhivyakesavan3
 
CH04.ppt
CH04.pptCH04.ppt
Cryptography and Network Security chapter 4.ppt
Cryptography and Network Security chapter 4.pptCryptography and Network Security chapter 4.ppt
Cryptography and Network Security chapter 4.ppt
the9amit
 
Lec_4.pdf
Lec_4.pdfLec_4.pdf
Lec_4.pdf
Mattupallipardhu
 
A study on number theory and its applications
A study on number theory and its applicationsA study on number theory and its applications
A study on number theory and its applications
Itishree Dash
 
DAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptxDAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptx
vaishnavi339314
 
555_Spring12_topic06.ppt
555_Spring12_topic06.ppt555_Spring12_topic06.ppt
555_Spring12_topic06.ppt
SnehSinha6
 
TABREZ KHAN.ppt
TABREZ KHAN.pptTABREZ KHAN.ppt
TABREZ KHAN.ppt
TabrezKhan733764
 
NumberTheory.ppt
NumberTheory.pptNumberTheory.ppt
NumberTheory.ppt
Dhandhan16
 
Chapter 2 Lecture Notes_ Divisibility.pdf
Chapter 2 Lecture Notes_ Divisibility.pdfChapter 2 Lecture Notes_ Divisibility.pdf
Chapter 2 Lecture Notes_ Divisibility.pdf
georgianabeauty02
 
Dynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain MultiplicationDynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain Multiplication
KrishnakoumarC
 
Number theoretic-rsa-chailos-new
Number theoretic-rsa-chailos-newNumber theoretic-rsa-chailos-new
Number theoretic-rsa-chailos-new
Christos Loizos
 
parameterized complexity for graph Motif
parameterized complexity for graph Motifparameterized complexity for graph Motif
parameterized complexity for graph Motif
AMR koura
 

Similar to ADVANCED ALGORITHMS-UNIT-3-Final.ppt (20)

Modular arithmetic
Modular arithmeticModular arithmetic
Modular arithmetic
 
Number theory
Number theoryNumber theory
Number theory
 
CH04.ppt
CH04.pptCH04.ppt
CH04.ppt
 
Cryptography and Network Security chapter 4.ppt
Cryptography and Network Security chapter 4.pptCryptography and Network Security chapter 4.ppt
Cryptography and Network Security chapter 4.ppt
 
Ch04
Ch04Ch04
Ch04
 
2.ppt
2.ppt2.ppt
2.ppt
 
Matdis 3.4
Matdis 3.4Matdis 3.4
Matdis 3.4
 
Lec_4.pdf
Lec_4.pdfLec_4.pdf
Lec_4.pdf
 
A study on number theory and its applications
A study on number theory and its applicationsA study on number theory and its applications
A study on number theory and its applications
 
DAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptxDAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptx
 
555_Spring12_topic06.ppt
555_Spring12_topic06.ppt555_Spring12_topic06.ppt
555_Spring12_topic06.ppt
 
ikh323-05
ikh323-05ikh323-05
ikh323-05
 
TABREZ KHAN.ppt
TABREZ KHAN.pptTABREZ KHAN.ppt
TABREZ KHAN.ppt
 
add math form 4/5
add math form 4/5add math form 4/5
add math form 4/5
 
NumberTheory.ppt
NumberTheory.pptNumberTheory.ppt
NumberTheory.ppt
 
Indices
IndicesIndices
Indices
 
Chapter 2 Lecture Notes_ Divisibility.pdf
Chapter 2 Lecture Notes_ Divisibility.pdfChapter 2 Lecture Notes_ Divisibility.pdf
Chapter 2 Lecture Notes_ Divisibility.pdf
 
Dynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain MultiplicationDynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain Multiplication
 
Number theoretic-rsa-chailos-new
Number theoretic-rsa-chailos-newNumber theoretic-rsa-chailos-new
Number theoretic-rsa-chailos-new
 
parameterized complexity for graph Motif
parameterized complexity for graph Motifparameterized complexity for graph Motif
parameterized complexity for graph Motif
 

Recently uploaded

ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 

Recently uploaded (20)

ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 

ADVANCED ALGORITHMS-UNIT-3-Final.ppt

  • 2. 2 Prime and composite numbers  The first 20 primes, in order, are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71  Example, 39 is composite because 3 | 39
  • 3. 3 Common divisors and greatest common divisors  If d is a divisor of a and d is also a divisor of b, then d is a common divisor of a and b.  For example:  The divisors of 30 are 1, 2, 3, 5, 6, 10, 15, and 30,  The divisors of 24 are 1, 2, 3, 6, 8, 12, and 24  and so the common divisors of 24 and 30 are 1, 2, 3, and 6.  The greatest common divisor of two integers a and b, not both zero, is the largest of the common divisors of a and b.  For example: gcd(24,30)=6
  • 4. 4  Greatest common divisor  Euclid’s algorithm used to compute greatest common divisors.
  • 5. 5 Example of the running of EUCLID, consider the computation of gcd (30,21)
  • 6. 6 EXAMPLE Calculate: gcd(22, 60) = gcd(60,22) 60 = 2 x 22 + 16 = Euclid(22,16) 22 = 1 x 16 + 6 = Euclid(16,6) 16 = 2 x 6 + 4 = Euclid(6,4) 6 = 1 x 4 + 2 = Euclid(4,2) 4 = 2 x 2 + 0 = Euclid(2,0) = 2.
  • 7. 7 The running time of Euclid’s algorithm  The overall running time of EUCLID is proportional to the number of recursive calls it makes.  The number of recursive calls in EUCLID is O(log b)
  • 8. 8 The extended form of Euclid’s algorithm  The procedure EXTENDED_EUCLID takes as input a pair of nonnegative integers and returns a triple of the form (d,x,y).
  • 9. 9 Figure : illustrates how EXTENDED-EUCLID computes gcd(99,78)
  • 10. 10 a b [a/b] d x y 99 78 Example: gcd(99,78)
  • 11. 11 a b [a/b] d x y 99 78 1 gcd(99,78)
  • 12. 12 a b [a/b] d x y 99 78 1 78 21 Remainder Example: gcd(99,78)
  • 13. 13 a b [a/b] d x y 99 78 1 78 21 3 Example: gcd(99,78)
  • 14. 14 a b [a/b] d x y 99 78 1 78 21 3 21 15 Remainder Example: gcd(99,78)
  • 15. 15 a b [a/b] d x y 99 78 1 78 21 3 21 15 1 15 6 2 6 3 2 3 0 - Example: gcd(99,78)
  • 16. 16 a b [a/b] d x y 99 78 1 78 21 3 21 15 1 15 6 2 6 3 2 3 0 - 3 1 0 Example: gcd(99,78) When b=0 , then d=b and initialize x=1 and y=0
  • 17. 17 a b [a/b] d x y 99 78 1 3 78 21 3 3 21 15 1 3 15 6 2 3 6 3 2 3 0 1 3 0 - 3 1 0 Example: gcd(99,78) For every step, calculate x and y Step 1: New x value = previous y value x=0 New y value = previous x value – ([a/b] * (previous y value) y= 1- (2*0) = 1
  • 18. 18 a b [a/b] d x y 99 78 1 78 21 3 21 15 1 15 6 2 3 1 -2 6 3 2 3 0 1 3 0 - 3 1 0 For every step, calculate x and y Step 2: New x value = previous y value x=1 New y value = previous x value – ([a/b] * (previous y value) y= 0- (2*1) = -2 Example: gcd(99,78)
  • 19. 19 a b [a/b] d x y 99 78 1 78 21 3 21 15 1 3 -2 3 15 6 2 3 1 -2 6 3 2 3 0 1 3 0 - 3 1 0 For every step, calculate x and y Step 3: New x value = previous y value x= -2 New y value = previous x value – ([a/b] * (previous y value) y= 1- (1*-2) = 3 Example: gcd(99,78)
  • 20. 20 a b [a/b] d x y 99 78 1 3 -11 14 78 21 3 3 3 -11 21 15 1 3 -2 3 15 6 2 3 1 -2 6 3 2 3 0 1 3 0 - 3 1 0 Example: gcd(99,78)
  • 21. 21  Since the number of recursive calls made in EUCLID is equal to the number of recursive calls made in EXTENDED-EUCLID, the running times of EUCLID and EXTENDED-EUCLID are the same, to within a constant factor.  That is, for a > b > 0, the number of recursive calls is O(log b).  Example: gcd(66, 24) = 6 gcd (899,493) =29 gcd (95,355) =5
  • 23. 23 1. Modular Arithmetic : a) Group : A group (S,) is a set S together with binary operation  defined on S for which the following properties hold : i) Closure : For all a, b  S, a  b  S. ii) Identity : There exists an element e  S, called the identity of the group,  a  e = e  a = a for all a  S. iii) Associativity : For all a, b, c  S, we have (a  b)  c = a  (b  c) iv) Inverse : For each a  S, there exists a unique element b  S, called the inverse of ‘a’, such that (a  b) = (b  a) = e
  • 24. 24 The familiar group (Z,+) of the integers Z under the operation of addition: 0 is the identity, and the inverse of a is -a. Abelian Group : A group (S,) is said to be ‘Abelian Group’, if it satisfies the commutative property. (a  b) = (b  a)
  • 25. 25 Finite Group : A group (S,) is said to be ‘Finite Group’, if it satisfies the property. |S| <  Sub-Group : If (S,) is a group, and S’  S and (S’,) is also a group, then (S’,) is a sub group of (S’,)
  • 26. 26 The groups defined by modular addition and multiplication For any positive integer n, let S be the complete set of residues {0, 1, 2,…, n−1}. Addition modulo n on S is defined as follows. For a and b in S, take the usual sum of a and b as integers, and let r be the element of S to which the result is congruent (modulo n); the sum a+b (mod n) is equal to r. (A + B) mod C = (A mod C + B mod C) mod C
  • 27. 27
  • 28. 28 The groups defined by modular addition and multiplication For example, addition modulo 5 is given by the following table: Finite group (Z6,+6) Additive group modulo n
  • 29. 29 The groups defined by modular addition and multiplication Multiplication modulo n is defined by taking ab (mod n) to be equal to s, where s is the element of S to which the usual product of a and b is congruent (modulo n). (A * B) mod C = (A mod C * B mod C) mod C
  • 30. 30 The groups defined by modular addition and multiplication For example, Multiplication modulo 15 is given by the following table: Finite group (Z15,*15) Multiplicative group modulo n
  • 32. 32 a x ≡ b (mod n) where a > 0 and n > 0. We assume that a, b, and n are given, and we wish to find all values of x, modulo n.
  • 33. 33
  • 34. 34 Example : a= 14 b= 30 and n=100 Step1: gcd(14 , 100) = (a, n) a b [a/b] d x y 14 100 100 14 7 2 1 -7 14 2 7 2 0 1 2 0 - 2 1 0 Solution of Extended Euclid Algorithm d= 2 x= 1 y= -7
  • 35. 35 Step 2: If d |b if 2 | 30 , yes it divides Then x0 = -7 ( 30/2) mod 100 = 95
  • 36. 36 Step 3: i=0 95 + 0 (100/2) mod 100 = 95 i=1 95 + 1 (100/2) mod 100 = 45 The loop on lines 4-5 prints the two solutions 95 and 45.
  • 37. 37 Assignment: 1. 35 x ≡ 10 (mod 50) Sol: x1 = 16, x2 = 26, x3 = 36, x4 = 46 x5=6 2. 56x ≡ 1 mod 93 Sol: x=5 3. 5x ≡ 12 mod 19 Sol: x=48 x=12 4. 15x ≡ 12 mod 57 Sol: x ≡ 16, 35 or 54 mod 57.
  • 39. 39  Around A.D. 100, the Chinese mathematician Sun-Ts˘u solved the problem of finding those integers x that leave remainders 2, 3, and 2 when divided by 3, 5, and 7 respectively.  One such solution is x =23  The “Chinese remainder theorem” provides a correspondence between a system of equations modulo a set of pairwise relatively prime moduli (for example, 3, 5, and 7) and an equation modulo their product (for example, 105).
  • 40. 40 1. x ≡ 2 (mod 5) x ≡ 3 (mod 13) Standard Equation : x ≡ a (mod n) Solution: a1= 2 a1 , a2 be integers a2= 3 n1= 5 n= n1,n2 …… nk, where the ni are pairwise relatively prime n2= 13 n = n1* n2 = 13*5 = 65 m1= n / n1 =13 moduli (m) m2= n / n2 = 5 Calculate : ci = mi (mi -1 mod ni)
  • 41. 41 1. x ≡ 2 (mod 5) x ≡ 3 (mod 13) Standard Equation : x ≡ a (mod n) Solution: a1=2 a2= 3 n1= 5 n2= 13 n = 65 m1=13 m2= 5 Calculate : ci = mi (mi -1 mod ni) c1 = m1 (m1 -1 mod n1) = 13 (13-1 mod 5) = 13 (2 mod 5) = 26 c2 = m2 (m2 -1 mod n2) = 5 (5-1 mod 13) = 5 (8 mod 13) = 40 x= (c1 *a1 + c2 *a2 ) mod n = (26* 2 + 40 * 3 ) mod 65 = (52 +120) mod 65 = 42 (mod 65) = 42
  • 42. 42 1. 13-1 (mod 5) = 13 * 0 ≡ 1 (mod 5) WRONG 13 * 1 ≡ 1 (mod 5) WRONG 13 * 2 ≡ 1 (mod 5) RIGHT The modular inverse of 13 (mod 5) is 13-1 is 2 A x ≡ 1 (mod C) The modular inverse of A (mod C) is A-1 2. 5 -1 (mod 13) = 5 * 0 ≡ 1 (mod 13) WRONG 5 * 1 ≡ 1 (mod 13) WRONG 5 * 2 ≡ 1 (mod 13) WRONG 5 * 3 ≡ 1 (mod 13) WRONG 5 * 4 ≡ 1 (mod 13) WRONG 5 * 5 ≡ 1 (mod 13) WRONG 5 * 6≡ 1 (mod 13) WRONG 5 * 7 ≡ 1 (mod 13) WRONG 5 * 8 ≡ 1 (mod 13) RIGHT
  • 43. 43 Find all solutions to the equations 1. x ≡ 2 (mod 5) x ≡ 3 (mod 13) 2. x ≡ 4 (mod 5) x ≡ 5 (mod 11) 3. x ≡ 6 (mod 11) x ≡ 13 (mod 16) Solu:51669 4. x ≡ 9 (mod 21) x ≡ 19 (mod 25) Solu:51669 5. x ≡ 1 (mod 5) x ≡ 2 (mod 7) Solu:1731 6. x ≡ 3 (mod 9) x ≡ 4 (mod 11) Solu: 1731
  • 44. 44 Powers of an Element
  • 45. 45 Consider the sequence of powers of ‘a’, modulo n where a ∊ Zn *. For example, i 0 1 2 3 4 5 6 7 8 9 3i mod 7 1 3 2 6 4 5 1 3 2 6 i 0 1 2 3 4 5 6 7 8 9 2i mod 7 1 2 4 1 2 4 1 2 4 1 Now, < 2 > = {1, 2, 4} in Z7 * < 3 > = {1, 3, 2, 6, 4, 5} in Z7 * Here, ord7 (2) = 3 & ord7 (3) = 6 Powers of an Element :
  • 46. 46 Compute : ab (mod n) Example: 7560 (mod 561) Is it possible using Calculator ? If yes, How much time? So, Use MODULAR-EXPONENTIATION algorithm
  • 47. 47 MODULAR-EXPONENTIATION (a, b, n) 1. c = 0 2. d = 1 3. Let (bk , bk-1 , …..,b1 , b0 ) 4. for i = k downto 0 5. c = 2c 6. d = (d.d) mod n 7. if bi = = 1 8. c = c + 1 9. d = (d.a) mod n 10. return d
  • 48. 48 Example: 7560 (mod 561) a=7 b= 560 n=561 Step 1: The binary representation of b =560 is 1000110000 k=10 (count of 1’s and 0’s) Step 2: c=0 d=1 for ( i = 10 downto 0 ) i=9 c= 2.c = 2.0 =0 d= (d*d) mod n = 1*1 mod 561 = 1 if b9 is 1 update c and d c= 0+1 =1 d= 1* 7 mod 561 = 7 Result of this step: c=1 d=7
  • 49. 49 i=8 c= 2.c = 2.1 =2 d= (d*d) mod n = 7*7 mod 561 = 49 if b8 is not 1 So don’t update c and d Result of this step: c=2 d=49 560 = 1000110000
  • 50. 50 i=7 c= 2.c = 2.2 =4 d= (d*d) mod n = 49*49 mod 561 = 157 if b7 is not 1 So don’t update c and d Result of this step: c=4 d=157 560 = 1000110000
  • 51. 51 Final result is 7560 (mod 561) = 1
  • 53. 53 In RSA Cryptosystem, the public and private keys are generated as follows : a) Select at random two large prime numbers p and q such that p ≠ q. b) Compute n = p*q n is used as the modulus for both the public and private keys. Its length, usually expressed in bits, is the key length.
  • 54. 54 c) Select a small odd integer ‘e’ that is relatively prime to ø(n)= (p-1 * q-1) (public exponent) d) Compute the integer ‘d’ (private exponent) from e, p and q such that d * e ≡ 1 mod ø(n)
  • 55. 55 e) Publish P = (e,n) RSA Public Key Keep Secret S = (d,n) RSA Secret Key Here, e = ENCRYPT(m) = me mod n d = DECRYPT(c) = cd mod n
  • 56. 56 Apply RSA algorithm for the following. p = 11 q = 29 e = 3 Encryption: Here n = pq = 319 (n) = p-1 * q-1 = 10 * 28 = 280 and d * e ≡ 1 mod 280 So, d = 187 Example: Consider an RSA key set with p = 11, q = 29, n = 319, and e = 3. What value of d should be used in the secret key? What is the encryption of the message M =100?
  • 57. 57 Hence, (e, n) = (3, 319) is the public key and (d, n) = (187, 319) is the private key. For M = 100, the cipher text is 1003 mod 319 = 254. Here, e = ENCRYPT(m) = me mod n d = DECRYPT(c) = cd mod n Decryption: the Plain text is 254187 mod 319 = 100.
  • 58. 58 Problems: Sl No. Message P Q E Cipher Plain Text 1. 7 11 3 ? ? ? 2. 88 17 11 ? ? ? 3. 513 137 131 ? ? ? 4. 123 61 53 ? ? ? 5. 148 23 37 ? ? ? 6. 42 13 19 ? ? ?
  • 59. 59 Problem with solution: Sl No. Message P Q E Cipher Plain Text 1. 7 11 3 3 13 7 2. 88 17 11 7 11 88 3. 513 137 131 3 8363 513 4. 123 61 53 17 855 123 5. 148 23 37 5 111 148 6. 42 13 19 7 120 42
  • 61. 61 Primality Testing : Methods for primality testing 1. Pseudoprimality testing 2. The Miller-Rabin randomized primality test The problem of finding large primes.
  • 62. 62 Pseudoprimality testing This procedure can make errors, but only of one type. That is, if it says that n is composite, then it is always correct. If it says that n is prime, however, then it makes an error only on specific cases. The first four such values are 341, 561, 645, and 1105. <10000
  • 63. 63
  • 65. 65 a) Carmichael number A Carmichael number is a composite positive integer which satisfies the following formula. bn-1 ≡ 1 ( mod n) for all integers ‘b’ which are relatively prime to ‘n’. The first Carmichael Number is : 561
  • 66. 66 MILLER-RABIN (n,s) for j = 1 to s a = RANDOM(1, n-1) if WITNESS (a,n) return COMPOSITE return PRIME  The Procedure MILLER-RABIN is a probabilistic search for a proof that n is composite.  In the following procedure, ‘s’ is the number of times the value of ‘a’ is to be chosen at random.
  • 67. 67 WITNESS(a,n) 1. Let t and u be such that t ≥ 1. u is odd, such that n-1 = 2t u 2. x0 = MODULAR-EXPONENTIATION(a,u,n) 3. for i = 1 to t 4. xi = x2 i-1 mod n 5. if ( xi = = 1) and ( xi-1 ≠ 1) and ( xi-1 ≠ n-1) 6. return TRUE 7. if xt ≠ 1 8. return TRUE 9. return FALSE
  • 68. 68 Example: Let ‘n’ be a carmichael number. n = 561 So, here n – 1 = 560 If n – 1 is written in the form of n-1 = 2t u, then t = 4 and u = 35 Let the value of ‘a’ is chosen from the algorithm as : 7 From the WITNESS algorithm, find the value of x0. Here, call the MODULAR_EXPONENTIATION(a,u,n) where a = 7 & u = 35 & n = 561
  • 69. 69 Here, d = ac mod n (c = b = u) From above, the value of ‘d’ returned is : 241 Here, x0 ≡ 735 ≡ 241 (mod 561). i init 5 4 3 2 1 0 bi -- 1 0 0 0 1 1 c 0 1 2 4 8 17 35 d 1 7 49 157 526 160 241
  • 70. 70 Here, d = ac mod n (c = b = u) From above, the value of ‘d’ returned is : 241 1. Here, x0 ≡ 735 ≡ 241 (mod 561). Note : Further we can have 2. 770 ≡ 298 (mod 561) = x1 3. 7140 ≡ 166 (mod 561) = x2 4. 7280 ≡ 67 (mod 561) = x3 5. 7560 ≡ 1 (mod 561) = x4
  • 71. 71 So, the sequence is : (241, 298, 166, 67, 1) Thus, WITNESS discovers 1 in the last squaring step, since a560 ≡ 1 (mod n) Therefore, a = 7 is the witness to the compo- siteness of ‘n’. WITNESS(7,N) returns TRUE. MILLER-RABIN returns COMPOSITE Note : 561 = 3 . 11 . 17
  • 72. 72 Error rate of the Miller-Rabin primality test is very less compared to Pseudoprimality testing
  • 74. 74 Integer Factorization : This is the process of integer factorization into a product of primes. Pollard’s rho heuristic : This heuristic here helps in finding the product of primes for the given integer. POLLARD-RHO(n) 1. i = 1 2. x1 = RANDOM(0, n-1) 3. y = x1 4. k = 2
  • 75. 75 5. While TRUE 6. i = i + 1 7. xi = (x2 i-1 - 1 ) mod n 8. d = gcd(y – xi , n) 9. if ( d  1) and (d  n) 10. print d 11. if ( i = = k) 12. y = xi 13. k = 2k Note : The above algorithm generates a set of factors which are primes for the given integer.
  • 76. 76 Example: Pollard’s Rho Heuristic Let n = 1387 So, Initialization : i = 1 x1 = 2 y = 2 k = 2 WHILE : STEP-1 : i= 2 xi = (x2 i-1 - 1 ) mod n  x2 = 3 d = gcd(y – xi , n)  d = 1 if [ (d  1) and ( d  n) ] FALSE if ( i = =k) TRUE y = 3 k = 4
  • 77. 77 STEP-2 : i= 3 xi = (x2 i-1 - 1 ) mod n  x3 = 8 d = gcd(y – xi , n)  d = 1 if [ (d  1) and ( d  n) ] FALSE if ( i = =k) FALSE STEP-3 : i= 4 xi = (x2 i-1 - 1 ) mod n  x4 = 63 d = gcd(y – xi , n)  d = 1 if [ (d  1) and ( d  n) ] FALSE if ( i = =k) TRUE y = 63 k = 8
  • 78. 78 STEP-4 : i= 5 xi = (x2 i-1 - 1 ) mod n  x5 = 1194 d = gcd(y – xi , n)  d = 1 if [ (d  1) and ( d  n) ] FALSE if ( i = = k) FALSE STEP-5 : i = 6 xi = (x2 i-1 - 1 ) mod n  x6 = 1186 d = gcd(y – xi , n)  d = 1 if [ (d  1) and ( d  n) ] FALSE if ( i = = k) FALSE
  • 79. 79 STEP-6 : i = 7 xi = (x2 i-1 - 1 ) mod n  x7 = 177 d = gcd(y – xi , n)  d = 19 if [ (d  1) and ( d  n) ] TRUE  Print d = 19 if ( i = = k) FALSE If the process is continued like this, we get another factor : 73 The relation among the Xi values are shown in the next slide :
  • 80. 80 310 996 396 814 84 x7 177 x6 1186 120 x5 1194 339 529 x4 63 595 1053 x3 8 x2 3 x1 2