Lecture 03
Lecture 03
Lecture 03
More on Mathematical
Foundations for Cryptography
By
Ritwik M
Assistant Professor(SrGr)
Dept. Of Computer Science & Engg.
Sources: Stallings William, Cryptography and Network Security: Principles and Practice, 7th Edition, Pearson/Prentice- Hall, 2018.; Forouzan B A, Cryptography and Network Security, Tata
McGraw Hill, 2007; The internet. All images from google images
Quick Recap
• Integer Arithmetic
• Greatest Common Divisor (GCD)
• Euclidean Algorithm to calculate GCD
• Examples
• Exercises
19CSE311 Ritwik M
Modular Arithmetic
19CSE311 Ritwik M
Modular Arithmetic cont.
• The modulo operator (mod) takes an integer (a) from the set Z and
a positive modulus (n).
• The modulo operator creates a nonnegative residue (r).
• Therefore
a mod n = r
19CSE311 Ritwik M
Modular Arithmetic - Example
• 27 mod 5
• Dividing 27 by 5 results in r = 2. This means that 27 mod 5 = 2.
• 36 mod 12
• Dividing 36 by 12 results in r = 0. This means that 36 mod 12 = 0.
• −18 mod 14
• Dividing −18 by 14 results in r = −4.
• However, we need to add the modulus (14) to make it nonnegative.
• We have r = −4 + 14 = 10. This means that −18 mod 14 = 10.
• −7 mod 10
• Dividing −7 by 10 results in r = −7.
• After adding the modulus to −7, we have r = 3. This means that −7 mod 10 = 3
19CSE311 Ritwik M
Modular Arithmetic - Exercise
• 271 mod 5
• 236 mod 12
• −184 mod 14
• −17 mod 10
• 23 mod 15
• -23 mod 100
19CSE311 Ritwik M
Congruence
• In cryptography, we often used the concept of congruence instead of equality
• To show that two integers are congruent, we use the congruence operator (≡).
• Add the phrase (mod n) to the right side of the congruence to define the value
of modulus that makes the relationship valid
• The congruence operator maps a member from Z to a member of Zn
• Example.
• 2 ≡ 12 (mod 10)
• 13 ≡ 23 (mod 10)
• 8 ≡ 13 (mod 5) −8 ≡ 2 ≡ 12 ≡ 22 (mod 10)
• 34 ≡ 24 (mod 10)
• 23 ≡ 33 (mod 5)
• −8 ≡ 12 (mod 10)
• −8 ≡ 2 (mod 5)
19CSE311 Ritwik M
Congruence - Properties
• The following properties allow us to first map the two inputs to Zn (if
they are coming from Z) before applying the three binary operations
(+, −, ×)
• Properties
• First Property: (a + b) mod n = [(a mod n) + (b mod n)] mod n
• Second Property: (a − b) mod n = [(a mod n) − (b mod n)] mod n
• Third Property: (a × b) mod n = [(a mod n) × (b mod n)] mod n
19CSE311 Ritwik M
Inverse
• Additive
• In Zn , two numbers a and b are additive inverses of each other if
•
a + b ≡ 0 (mod n)
19CSE311 Ritwik M
Extended Euclidean Algorithm
• Given two integers a and b, the aim is to find two integers, s and t,
such that
s × a + t × b = gcd (a, b)
• The extended Euclidean algorithm can calculate both the gcd (a, b)
and the value of s and t simultaneously
• The algorithm can also find the multiplicative inverse of an integer
in modular arithmetic
19CSE311 Ritwik M
Extended Euclidean Algorithm Cont.
The Process
• By reversing the steps in the Euclidean algorithm, it is
possible to find these integers s and t.
• The whole idea is to start with the GCD and recursively
work our way backwards. The Algorithm
19CSE311 Ritwik M
Extended Euclidean Algorithm Cont.
• Step 1: Ensure inverse exists I.e GCD(b,a)=1
• The formulae
• rn+1 = rn-1 - q*rn • The last value of u n+1 and vn+1
• un+1 = un-1 - q*un correspond to the values s and t
• vn+1 = vn-1 - q*vn • The inverse is one of them
1 1 10 7 3 1 0 1 0 1 -1
2 2 7 3 1 0 1 -2 1 -1 3
•
3 3 3 1 0
19CSE311 Ritwik M
Example2 : Inverse using extended Euclidean Algorithm
• Calculate 23-1 in z100
Iteration q rn-1 rn rn+1 un-1 un un+1 vn-1 vn vn+1
1 4 100 23 8 1 0 1 0 1 -4
2 2 23 8 7 0 1 -2 1 -4 9
• 3 1 8 7 1 1 -2 3 -4 9 -13
4 7 7 1 0
19CSE311 Ritwik M
Summary
• Modular Arithmetic
• Congruence
• Inverse
• Extended Euclidean Algorithm to calculate Inverse
• Examples
• Exercises
19CSE311 Ritwik M
Up Next..
19CSE311 Ritwik M