0% found this document useful (0 votes)
101 views18 pages

Lecture 03

The document discusses modular arithmetic, congruence, inverses, and the extended Euclidean algorithm. It provides examples and exercises for calculating inverses using the extended Euclidean algorithm in modular arithmetic.

Uploaded by

DEVA SUNDER S J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views18 pages

Lecture 03

The document discusses modular arithmetic, congruence, inverses, and the extended Euclidean algorithm. It provides examples and exercises for calculating inverses using the extended Euclidean algorithm in modular arithmetic.

Uploaded by

DEVA SUNDER S J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

19CSE311 :Computer Security

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

• The division relationship (a = q × n + r)


(discussed previously section) has two inputs (a and n) and two
outputs (q and r).In modular arithmetic
• In modular arithmetic, we are interested in only one of the outputs,
the remainder r.
• i.e. we want to know what is the value of r when we divide a by n.
• This implies that we can change the above relation into a binary operator
with two inputs a and n and one output r.

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)

• In Zn , the additive inverse of a can be calculated as b = n − a.


• Multiplicative
• In Zn , two numbers a and b are multiplicative inverses of each other if
a x b ≡ 1 (mod n)

• For example, if the modulus is 10,


• the multiplicative inverse of 3 is 7. i.e. (3 × 7) mod 10 = 1.
• 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.
19CSE311 Ritwik M
Importance of Inverse

• It can be proved that a has a multiplicative inverse in Z n if and


only if GCD (b, a) = 1.
• In mathematics, two integers a and n are coprime (relatively prime
/ mutually prime) if the only positive integer that is a divisor of
both of them is 1
• Consequently, any prime number that divides a does not divide b, and
vice versa.
• This is equivalent to their GCD being 1
• The concept of prime and co-prime numbers is critical for most
cryptographic systems

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

• At the start of the iterations set:


• r0 = a
• r1 = b
• n = 1
• u0 = 1
• u1 = 0
• v0 = 0
• v1 = 1
19CSE311 Ritwik M
Example : Inverse using extended Euclidean Algorithm
• Calculate 7-1 in z10
Iteration q rn-1 rn rn+1 un-1 un un+1 vn-1 vn vn+1

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

U n+1 = -2 and vn+1 = 3


Check (7x–2) mod 10 = -14 mod 10 = 4mod 10
check (7x3)mod 10 = 21 mod 10 = 1 mod 10 --> success
Therefore 7-1 in Z10 is 3

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

U n+1 = 3 and v n+1 = -13


Check (23x3) mod 100 = 69 mod 100
check (23x-13)mod100 = [(23mod100) x (87 mod 100)]mod 100
= 2001 mod100 = 1mod100--> success
Z should be positive. -13 mod 100 ≡ 87 mod 100
Therefore 23-1 in Z100 is 87
19CSE311 Ritwik M
Inverse using extended Euclidean Algorithm - Exercises

• Calculate 23-1 in Z100


• Calculate 12-1 in Z26
• Calculate 1432-1 in Z123211
• Calculate 2317-1 in Z123456
• Calculate 2312-1 in Z12454

19CSE311 Ritwik M
Summary

• Modular Arithmetic
• Congruence
• Inverse
• Extended Euclidean Algorithm to calculate Inverse
• Examples
• Exercises

19CSE311 Ritwik M
Up Next..

Even More Mathematical Foundations for Cryptography

19CSE311 Ritwik M

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy