Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

19CSE311 :Computer Security

Lecture 04
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

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

19CSE311 Ritwik M
Primes
• The positive integers can be divided into three groups:
• the number 1, primes, and composites
• Co- primes:
• Two positive integers, a and b, are relatively prime, or coprime, if gcd (a, b) = 1.
• The number 1 is relatively prime with any integer
• If p is a prime, then all integers 1 to p − 1 are relatively prime to p
• cryptography uses primes and co-primes extensively
• So, Is there a finite number of primes or is the list infinite?
• Given a number n, can you find out how many primes are
smaller than or equal to n?

19CSE311 Ritwik M
To find number of Primes

• The function called π(n) is defined that finds the number of primes
smaller than or equal to n
• However, for large values for n, only approximation works.
• The greatest common divisor of two positive integers is the largest
integer that can divide both integers.
• It has been shown that [n/(ln n)]< π(n) <[n/(ln n − 1.08366)]
• Gauss discovered the upper limit; Lagrange discovered the lower limit.

19CSE311 Ritwik M
Checking for Primes & Co-Primes

• Primes
• Sieve of Eratosthenes
• Given a number n, check if the number is divisible by all primes less than √n
• Co-Primes
• Euler’s Phi-Function (or Euler’s totient function)
• φ(n)

19CSE311 Ritwik M
Sieve of Eratosthenes - Example

• Given a number n=100, √n = 10


• Check if any number less than 100 is divisible by 2, 3, 5,
and 7
• Cross out all numbers divisible by 2 (except 2 itself).
• Cross out all numbers divisible by 3 (except 3 itself).
• Cross out all numbers divisible by 5 (except 5 itself).
• Cross out all numbers divisible by 7 (except 7 itself).
• The numbers remaining are the prime numbers

19CSE311 Ritwik M
Euler’s Phi-Function
• Given an integer n, The function finds the number of integers that
are both smaller than n and relatively prime to n
• The following rules helps to find the value of φ(n).
• Rule 1: φ(1) = 0.
• Rule 2: φ(p) = p − 1 if p is a prime.
• Rule 3: φ(m × n) = φ(m) × φ(n) if m and n are relatively prime.
• Rule 4: φ(pe ) = pe − p(e−1) if p is a prime

19CSE311 Ritwik M
Euler’s Phi-Function - Example
• What is the value of φ(13)?

19CSE311 Ritwik M
Euler’s Phi-Function - Example
• What is the value of φ(13)?
• Because 13 is a prime, φ(13) = (13 −1) = 12 --> Rule 2

19CSE311 Ritwik M
Euler’s Phi-Function - Example
• What is the value of φ(13)?
• Because 13 is a prime, φ(13) = (13 −1) = 12 --> Rule 2
• What is the value of φ(10)?

19CSE311 Ritwik M
Euler’s Phi-Function - Example
• What is the value of φ(13)?
• Because 13 is a prime, φ(13) = (13 −1) = 12 --> Rule 2
• What is the value of φ(10)?
• φ(10) = φ(2) × φ(5) --> Using rule 3
= 1 × 4 = 4 -->Using rule 2 (because 2 and 5 are primes)

19CSE311 Ritwik M
Euler’s Phi-Function - Example
• What is the value of φ(13)?
• Because 13 is a prime, φ(13) = (13 −1) = 12 --> Rule 2
• What is the value of φ(10)?
• φ(10) = φ(2) × φ(5) --> Using rule 3
= 1 × 4 = 4 -->Using rule 2 (because 2 and 5 are primes)
• What is the value of φ(240)?

19CSE311 Ritwik M
Euler’s Phi-Function - Example
• What is the value of φ(13)?
• Because 13 is a prime, φ(13) = (13 −1) = 12 --> Rule 2
• What is the value of φ(10)?
• φ(10) = φ(2) × φ(5) --> Using rule 3
= 1 × 4 = 4 -->Using rule 2 (because 2 and 5 are primes)
• What is the value of φ(240)?
• 240 = 24 × 31 × 51
• Therefore
φ(240)=(24 − 23) × (31 − 30) × (51 − 50) = 64-->Using Rule 4

19CSE311 Ritwik M
Euler’s Phi-Function – Lessons Learnt
• The value of φ(n) for large composites can be found only if the
number n can be factored into primes.
• This implies that the difficulty of finding φ(n) depends on the
difficulty of finding the factorization of n

19CSE311 Ritwik M
Fermat’s Little Theorem
• Plays a very important role in number theory and cryptography
• It is helpful for quickly finding a solution to some exponentiations
• Two versions of theorem
• If p is a prime and a is an integer such that p does not divide a, then
a(p−1) ≡ 1 mod p
• if p is a prime and a is an integer, then ap ≡ a mod p
• This second version removes the condition on a

19CSE311 Ritwik M
Fermat’s Little Theorem - Example
• Find the result of 6 10 mod 11.
• This is the first version of Fermat’s little theorem where p = 11.
• So 610 mod 11 = 1
• Find the result of 3 12 mod 11.
• Here the exponent (12) and the modulus (11) are not the same
• With substitution this can be solved using second version of Fermat’s little
theorem
• 312 mod 11 = (311 × 3) mod 11 = (311 mod 11) (3 mod
11) = (3 × 3) mod 11 = 9

19CSE311 Ritwik M
Fermat’s Little Theorem – Another Application
• Used for finding some multiplicative inverses quickly
• It is helpful for quickly finding a solution to some exponentiations
• Statement
• If p is a prime and a is an integer such that p does not divide a, then
a(−1) mod p≡ a(p−2) 1 mod p
• Example:
• 8−1 mod 17 = 817−2 mod 17 = 815 mod 17
= (85 mod17 × 85 mod17× 83 mod17× 82 mod17) mod 17
= (9 mod17 × 9 mod17 × 2 mod17 × 13 mod17 )
= 2106 mod17 = 15 mod 17

19CSE311 Ritwik M
Exercise

• Calculate the inverse for the following


• 5−1 mod 23
• 60−1 mod 101
• 22−1 mod 211

19CSE311 Ritwik M
Eulers Theorem
• Plays a very important role in RSA cryptosystem
• This can be thought of as a generalization of Fermat’s little theorem
• It removes the condition that a and n should be coprime
• Statements
• If a and n are coprime, then aφ(n) ≡ 1 (mod n).
• If n = p × q, a < n, and k an integer, then :
a(k × φ(n)+1) ≡ a (mod n)
• if p is a prime and a is an integer, then ap ≡ a mod p
• This second version removes the condition on a

19CSE311 Ritwik M
Summary

• Importance of primes and co primes


• Checking for primes and co primes
• Sieve of Eratosthenes
• Eulers phi function
• Fermat littles theorem
• Eulers theorem
• Examples
• Exercises

19CSE311 Ritwik M
Up Next..

Introduction to Cryptography

19CSE311 Ritwik M

You might also like