Module 1
Module 1
Network Security
PREPARED BY
DR. L.MARY SHAMALA
ASSISTANT PROFESSOR
SCOPE/VIT
Course Objectives
1. To explore the concepts of number theory and
cryptography techniques.
2. To understand Hash, Message Authentication Code,
Digital Signatures, and authentication protocols.
3. To know the fundamentals of Transport layer security,
Web Security, Email Security, and various types of System
Security
VIT/SCOPE/BCSE309-CNS/MODULE 1 2
Course Outcomes
1. To know the fundamental mathematical concepts related
to security.
2. To understand the concept of various cryptographic
techniques.
3. To apprehend the authentication and integrity process of
data for various applications.
4. To know the fundamentals of Transport layer security,
web security, E-Mail Security, and IP Security.
VIT/SCOPE/BCSE309-CNS/MODULE 1 3
Syllabus
Module:1 Fundamentals of Number Theory
Module:2 Symmetric Encryption Algorithms
Module:3 Asymmetric Encryption Algorithms and Key Exchange
Module: 4 Message Digest and Hash Functions
Module:5 Digital Signature and Authentication Protocols
Module: 6 Transport Layer Security and IP Security
Module:7 E-Mail, Web, and System Security
Module:8 Contemporary Issues
VIT/SCOPE/BCSE309-CNS/MODULE 1 4
Textbook
“Cryptography and Network Security”
Author: William Stallings
Publisher: Pearson Education, 8th Edition, 2020.
Reference Book
“Cryptography and Network security”,
Authors: Behrouz A. Forouzan , Debdeep Mukhopadhyay
Publisher: Mcgraw Hill Education, 3nd Edition, 2015.
VIT/SCOPE/BCSE309-CNS/MODULE 1 5
Module I
FUNDAMENTALS OF NUMBER THEORY
VIT/SCOPE/BCSE309-CNS/MODULE 1 6
Topics
➢ Finite Fields and Number Theory
➢ Euclidian Algorithm
➢ Modular arithmetic
➢ Primality Testing
➢ Fermat’s and Euler’s theorem
➢ Chinese Reminder theorem
➢ Discrete Logarithms
VIT/SCOPE/BCSE309-CNS/MODULE 1 7
Number Theory
➢ Number theory is about integers and their properties.
➢ A set of integers, Z contains all integral numbers from
negative to positive infinity.
➢ Basic principles
▪ Divisibility and division algorithm
▪ Greatest common divisors
▪ Modular arithmetic
➢ Some relevant algorithms
VIT/SCOPE/BCSE309-CNS/MODULE 1 8
Divisors and Divisibility
➢ Let a and b be two integers
➢ We say a non-zero number a divides b if there exists an
integer m such that b = ma
➢ The notation a|b means a is divisor of b
➢ Example: Divisors of 24
➢ The integer 1 has only one divisor, itself.
➢ Every integer b>1 has at least two positive divisors: 1 and
b
VIT/SCOPE/BCSE309-CNS/MODULE 1 9
Divisors and Divisibility…
➢ Proper divisor of a
▪ A positive divisor not equal to a itself
▪ Example: 13|182
➢ Nontrivial divisor of a
▪ A positive divisor not equal to 1 or a
VIT/SCOPE/BCSE309-CNS/MODULE 1 10
Divisibility Properties
➢ For integers a, b, and c, it is true that:
1) If a|1, then a =±1.
2) If a|b and b|a, then a = ±b.
3) Any b ≠ 0 divides 0.
4) If a|b and b|c, then a|c
5) If a|b and a|c, then a|(mb + nc) for arbitrary integers
m and n.
VIT/SCOPE/BCSE309-CNS/MODULE 1 11
Division Algorithm
VIT/SCOPE/BCSE309-CNS/MODULE 1 12
The Relationship a = qn + r ,0 ≤ 𝑟 < 𝑛
VIT/SCOPE/BCSE309-CNS/MODULE 1 13
Prime Number
➢ A positive integer p greater than 1, which has no positive divisors
other than 1 and p is called prime number.
➢ A number is called composite if it has at least one nontrivial divisor.
VIT/SCOPE/BCSE309-CNS/MODULE 1 14
Greatest Common Divisors
➢ Let a and b be two integers, both not equal to zero.
➢ The greatest common divisor of a and b is the largest
integer that divides both a and b.
➢ It is denoted by gcd(a, b)
➢ Formal Definition: The positive integer d is said to be the
gcd of a and b if:
1) d is a divisor of a and of b.
2) Any divisor of a and b is a divisor of d
VIT/SCOPE/BCSE309-CNS/MODULE 1 15
Example 1
➢What is gcd(48, 72) ?
VIT/SCOPE/BCSE309-CNS/MODULE 1 16
Greatest Common Divisors…
Using prime factorizations
➢ a = p1a1 p2a2 … pnan , b = p1b1 p2b2 … pnbn ,
where p1 < p2 < … < pn and ai, bi N for 1 i n
➢ gcd(a, b) = p1min(a1, b1 ) p2min(a2, b2 ) … pnmin(an, bn )
➢ Example
a = 60 = 22 31 51
b = 54 = 21 33 50
gcd(a, b) = 21 31 50 = 6
VIT/SCOPE/BCSE309-CNS/MODULE 1 17
Euclidean Algorithm
➢ The Euclidean algorithm finds the Euclid(a, b: positive integers, int gcd)
greatest common divisor of two begin
integers very efficiently. int r
➢ It is based on the following theorem: a = |a|
1. If b = 0, then gcd(a, b) = |a|. ie, b = |b|
gcd(a,0)=a while (b != 0)
2. If b ≠0, then gcd(a, b) = gcd(|b|, a r = a%b
mod |b|). a=b
➢ Let us take a mod |b| as r b=r
end while
gcd = a
end
VIT/SCOPE/BCSE309-CNS/MODULE 1 18
VIT/SCOPE/BCSE309-CNS/MODULE 1 19
Example 1
➢ Compute gcd(100,35)
➢ Solution
▪ a=100;b=35 q a b r
▪ gcd(100,35) = 5
2 100 35 30
1 35 30 5
6 30 5 0
VIT/SCOPE/BCSE309-CNS/MODULE 1 20
Example 2
➢ Find the greatest common divisor of 2740 and 1760
q a b r
➢ Solution
▪ Given : a= 2740; b = 1760 1 2740 1760 980
▪ gcd (2740, 1760) = 20 1 1760 980 780
1 980 780 200
3 780 200 180
1 200 180 20
9 180 20 0
VIT/SCOPE/BCSE309-CNS/MODULE 1 21
Practice
Compute
1) gcd(1970,1066)
2) gcd(803,154)
VIT/SCOPE/BCSE309-CNS/MODULE 1 22
Relatively Prime Integers
Definition
Two integers a and b are relatively prime if and only if their
only common positive integer factor is 1
That is , gcd(a, b) = 1.
Example
gcd(8,15) = 1
Hence 8 & 15 are relatively prime
VIT/SCOPE/BCSE309-CNS/MODULE 1 23
Practice
╸Are 15 and 28 relatively prime?
Yes, gcd(15, 28) = 1.
╸Are 55 and 28 relatively prime?
Yes, gcd(55, 28) = 1.
╸Are 35 and 28 relatively prime?
No, gcd(35, 28) = 7.
VIT/SCOPE/BCSE309-CNS/MODULE 1 24
Pairwise Relatively Prime Integers
Definition
The integers a1, a2, …, an are pairwise relatively prime if gcd(ai, aj) = 1
whenever 1 i < j n.
Examples
Are 15, 17, and 27 pairwise relatively prime?
No, because gcd(15, 27) = 3.
Are 15, 17, and 28 pairwise relatively prime?
Yes, because gcd(15, 17) = 1, gcd(15, 28) = 1 and gcd(17, 28) = 1.
VIT/SCOPE/BCSE309-CNS/MODULE 1 25
Modular Arithmetic
Why do we need to study modular arithmetic?
◦ Extremely important for asymmetric cryptography (RSA, elliptic curves
etc.)
◦ Some historical ciphers can be elegantly described with modular
arithmetic (Caesar and affine cipher etc).
VIT/SCOPE/BCSE309-CNS/MODULE 1 26
Modular Arithmetic…
╸
VIT/SCOPE/BCSE309-CNS/MODULE 1 27
Modular Arithmetic…
➢ Mod takes an integer a from the set Z and a positive
modulus n and creates a non-negative residue r.
a mod n = r
➢ Example
▪ 11 mod 7
▪ -11mod 7
VIT/SCOPE/BCSE309-CNS/MODULE 1 28
Practice
➢ Find the result of the following operations:
▪ 27 mod 5
▪ 36 mod 12
▪ -18 mod 14
▪ -7 mod 10
VIT/SCOPE/BCSE309-CNS/MODULE 1 29
Modular Arithmetic…
➢ Set of Residues: Zn
o The result of the modulus operation with modulus n is always
an integer between 0 and n-1.
o Modulus operation creates a set called set of least residue
modulo n or Zn
o There are infinite instances of the set of residues (Zn), one for
each value of n.
o Some Zn sets
▪ Z2= { 0, 1}
▪ Z6 ={ 0, 1, 2, 3, 4, 5}
▪ Z11 ={0, 1, 2, 3, 4, 5,6,7,8,9,10}
VIT/SCOPE/BCSE309-CNS/MODULE 1 30
Modular Arithmetic…
➢ Can do modular arithmetic with any group of integers
➢ Operations in Zn
▪ Addition
▪ Subtraction
▪ Multiplication
➢ The inputs can be members from Z or Zn
➢ Example: Add 11 to 15 in Z8
▪ (11+15)mod 8= 26 mod 8=2
VIT/SCOPE/BCSE309-CNS/MODULE 1 31
Practice
1. Subtract 11 from 15 in Z8
2. Multiply 11 by 15 in Z8
3. Perform the following operations:
▪ Add 17 to 27 in Z14
▪ Subtract 34 from 12 in Z13
▪ Multiply 123 by -10 in Z19
VIT/SCOPE/BCSE309-CNS/MODULE 1 32
Modular Arithmetic…
➢ Properties of Modular Arithmetic
1.(a+b)mod n = [a mod n + b mod n]mod n
2.(a-b)mod n = [a mod n - b mod n]mod n
3.(a×b)mod n = [a mod n × b mod n]mod n
➢ Application of properties
▪ (1,723,345 + 2,124,945) mod 11
▪ (1,723,345 - 2,124,945) mod 11
▪ (1,723,345 × 2,124,945) mod 11
VIT/SCOPE/BCSE309-CNS/MODULE 1 33
Modular Arithmetic…
(1,723,345+2,124,945)mod11
=[1,723,345 mod 11+2,124,945 mod 11]mod 11
=[8+9]mod11
=17mod11
=6
VIT/SCOPE/BCSE309-CNS/MODULE 1 34
Modular Arithmetic…
➢ Modular arithmetic is like ordinary arithmetic. It is:
▪ Commutative (for addition and multiplication)
a+b=b+a
▪ Associative
(a + b) + c = a + (b + c)
▪ Distributive
a(b + c) = (ab) + (ac)
(b + c)a = (ba) + (ca)
VIT/SCOPE/BCSE309-CNS/MODULE 1 35
Recall
➢ Z is the set of all integers
➢ Zn is the set of integers mod n
▪ Z10 = {0,1,2,3,4,5,6,7,8,9}
➢ Zn* is defined as the set of mod n integers that are
relatively prime to n
▪ Z10* = {1,3,7,9} [0 is missing because gcd (0, 10) = 10]
VIT/SCOPE/BCSE309-CNS/MODULE 1 36
Congruences
➢ In cryptography, the concept of congruence is used instead of
equality.
➢ Mapping from Z to Zn is not one-to-one
➢ Example: The result of 2 mod 10=2, 12 mod 10 =2, 22 mod 2=2
and so on.
➢ In modular arithmetic, integers like 2, 12, and 22 are called
congruent mod 10.
➢ Congruence operator ≡ is used to show that two integers are
congruent
VIT/SCOPE/BCSE309-CNS/MODULE 1 37
Congruences…
➢ Two integers, a and b are said to be congruent modulo n,
if a mod n = b mod n.
➢ We use the notation a b (mod n) to indicate that a is
congruent to b modulo n.
➢ In other words, a is congruent to b modulo n if n divides
a – b.
➢ Example:
10 2 (mod 4) because 4 | (10 − 2)
VIT/SCOPE/BCSE309-CNS/MODULE 1 38
Practice
➢ 13 ?(mod 10)
➢ ? 12 (mod 10)
➢ 100 ? mod 11
➢ 73 ? (mod 23)
➢ 21 ? (mod 10)
➢ ? 13 (mod 5)
VIT/SCOPE/BCSE309-CNS/MODULE 1 39
Residue Classes
➢ A residue class [a] or [a]n is the set of integers congruent
modulo n.
➢ It is the set of all integers such that x=a (mod n)
➢ Example
▪ If n=5, we have 5 sets [0],[1], [2],[3], and [4]
▪ [0]={…,-15,-10,-5, 0, 5, 10, 15,…}
▪ [1]={…,-14,-9,-4, 1, 6, 11, 16,…}
▪ [2]= {…,-13,-8,-3, 2, 7, 12, 17,…}
▪ [3]={…,-12,-7, -5, 3, 8, 13, 18,…}
▪ [4]={…,-11,-6, -1, 4, 9, 14, 19,…}
VIT/SCOPE/BCSE309-CNS/MODULE 1 40
Modulo 7 Example
...
-21 -20 -19 -18 -17 -16 -15
-14 -13 -12 -11 -10 -9 -8
-7 -6 -5 -4 -3 -2 -1
0 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 32 33 34
...
VIT/SCOPE/BCSE309-CNS/MODULE 1 41
Congruences…
Examples
╸Is it true that 46 68 (mod 11) ?
Yes, because 11 | (46 – 68).
╸Is it true that 46 68 (mod 22)?
Yes, because 22 | (46 – 68).
╸For which integers z is it true that z 12 (mod 10)?
It is true for any z{…,-28, -18, -8, 2, 12, 22, 32, …}
VIT/SCOPE/BCSE309-CNS/MODULE 1 42
Congruences…
➢ Note some peculiarities
▪ If (a+b)≡(a+c) mod n then b≡c mod n
▪ If(ab)≡(ac) mod n then b≡c mod n only if
a is relatively prime to n
VIT/SCOPE/BCSE309-CNS/MODULE 1 43
Solving Linear Congruences
To Solve ax b (mod n)
╸ Assume gcd(a,n)=d
╸ If 𝑑 ∤ 𝑏, there is no solution
╸ Else there are d solutions. Use the following steps to find the
solutions:
1. Reduce the equation by dividing both sides of the equation by d
2. Multiply both sides of the reduced equation by the multiplicative
inverse of a to find a particular solution x0
3. The general solutions are:
𝑛
𝑥 = 𝑥0 + 𝑘 𝑓𝑜𝑟 𝑘 = 0,1,2, … , (𝑑 − 1)
𝑑
VIT/SCOPE/BCSE309-CNS/MODULE 1 44
Examples
1. Solve the equation 10x 2 (mod 15)
2. Solve the equation 14x 12 (mod 18)
VIT/SCOPE/BCSE309-CNS/MODULE 1 45
Additive inverse
➢ In Zn, two numbers a and b are additive inverses of each other
if a+b 0 (mod n)
➢ Additive inverse of a can be calculated as: b= n-a
➢ Example: Additive inverse of 4 in Z10 is 10-4=6
➢ Each integer has an additive inverse and its inverse is unique
➢ Each number has one and only one additive inverse
➢ An inverse of a number may be the number itself.
➢ Find all additive inverse pairs in Z10
VIT/SCOPE/BCSE309-CNS/MODULE 1 46
Multiplicative inverse
➢ In Zn, two numbers a and b are the multiplicative inverse
of each other if a×b 1 (mod n)
➢ Example: Multiplicative inverse of 3 is 7 in Z10 as 3×7 1
(mod n)
➢ Theorem: [a]n has a multiplicative inverse if and only if
gcd(a,n) = 1
➢ We use Zn* to denote the set of all residue classes that
have a multiplicative inverse.
VIT/SCOPE/BCSE309-CNS/MODULE 1 47
Extended Euclid Algorithm
➢ Given two integers a and b, there exists two integers, s
and t, such that:
s × a + t × b = gcd (a, b)
VIT/SCOPE/BCSE309-CNS/MODULE 1 48
Extended Euclid Algorithm…
➢ Process Involved
VIT/SCOPE/BCSE309-CNS/MODULE 1 49
Extended Euclid Algorithm…
VIT/SCOPE/BCSE309-CNS/MODULE 1 50
Example 1
➢ Given a = 161 and b = 28, find gcd (a, b) and the values of s and t.
➢ Solution
r = r1 − q × r2
s = s 1 − q × s2
t = t1 − q × t2
VIT/SCOPE/BCSE309-CNS/MODULE 1 52
Finding Multiplicative Inverse…
➢ Now apply the modulo operator to both sides.
▪ (s × n + b × t) mod n = 1 mod n
▪ [(s × n) mod n] + [(b × t) mod n] = 1 mod n
▪ 0 + [(b × t) mod n] = 1
▪ (b × t) mod n = 1 → This means t is the multiplicative inverse of b
in Zn
➢ The multiplicative inverse of b is the value of t after being
mapped to Zn.
VIT/SCOPE/BCSE309-CNS/MODULE 1 53
Addition and Multiplication Tables
VIT/SCOPE/BCSE309-CNS/MODULE 1 54
Example 2
➢ Find the multiplicative inverse of 11 in Z26.
➢ Solution :Use a table with r1 = 26 and r2 = 11.
➢ The gcd (26, 11) is 1, which means that the multiplicative inverse of 11
exists.
➢ Here, t1 = −7. The multiplicative inverse is (−7) mod 26 = 19
VIT/SCOPE/BCSE309-CNS/MODULE 1 55
Practice
1. Find the multiplicative inverse of 8 in Z10.
2. Find all multiplicative inverses in Z10
3. Find all multiplicative inverse pairs in Z11
4. Find the multiplicative inverse of 12 in Z26
5. Find the multiplicative inverse of 38 in Z180
VIT/SCOPE/BCSE309-CNS/MODULE 1 56
Modular Arithmetic: Exponentiation
➢ Exponentiation is performed by repeated multiplication, as in ordinary
arithmetic.
➢ For example, instead of performing the calculation
a n mod m = (a • a • a • a • • a )
➢ we can perform fewer multiplications and use intermediate modular
reductions.
➢ Example: To calculate a8 mod n, proceed as follows:
a 8 mod m = ((a 2 mod m) 2 mod m) 2 mod m
➢ Similarly:
a16 mod m = (((a 2 mod m) 2 mod m) 2 mod m) 2 mod m
a 25 mod m = (((((((a 2 mod m) • a) mod m) 2 mod m) 2 mod m) 2 mod m) • a) mod m
VIT/SCOPE/BCSE309-CNS/MODULE 1 57
Modular Arithmetic: Exponentiation…
➢ To calculate x11 mod n for some integers x and n.
▪ x11 = x1+2+8 = (x)(x2 )(x8 )
▪ First, compute x mod n, x2 mod n, x4 mod n, and x4 mod n
▪ Then calculate [(x mod n) * (x2 mod n) * (x8 mod n)] mod
n.
VIT/SCOPE/BCSE309-CNS/MODULE 1 58
Modular Arithmetic: Exponentiation…
➢ To find 117 mod 13, we can proceed as follows:
▪ 112 = 121 4 (mod 13)
▪ 114 = (112 ) 2 4 2 3 (mod 13)
▪ 117 = 11 * 112 * 114
▪ 117 11 * 4 * 3 132 2 (mod 13)
➢ 1722 mod 21
VIT/SCOPE/BCSE309-CNS/MODULE 1 59
Fast Exponentiation
➢ Fast exponentiation is possible using the square-and-multiply
method.
➢ The main idea behind this method is to treat the exponent as a
binary number of k bits
➢ More generally, to find the value ab mod n with a, b, and n
positive integers.
➢ If we express b as a binary number bkbk-1 … b0, then
VIT/SCOPE/BCSE309-CNS/MODULE 1 60
Fast Exponentiation Algorithm
The algorithm for computing ab mod n:
VIT/SCOPE/BCSE309-CNS/MODULE 1 64
Fermat’s Little Theorem
➢ Plays a very important role in number theory and
cryptography.
➢ Fermat's Little Theorem states:
1. If p is a prime number and a is an integer that does not divide
p, then ap-1 1 (mod p)
2. If p is a prime and a is an integer, then ap a (mod p)
*Pierre de Fermat (1601 - 1665), French mathematician most famous for Fermat's
Last Theorem, which was considered one of mathematics' most difficult theorems, and
has only recently been finally proven. His Little Theorem has nothing to do with his
Last Theorem.
VIT/SCOPE/BCSE309-CNS/MODULE 1 65
Fermat’s Little Theorem…
➢ Applications
▪ Helpful for quickly finding a solution to some
exponentiations.
▪ Finding some multiplicative inverses quickly if the modulus
is a prime
VIT/SCOPE/BCSE309-CNS/MODULE 1 66
Example 1
➢ Find the result of 610 mod 11.
➢ Solution
▪ Given: a=6; p=11
▪ Fermat’s Little Theorem: ap-1 1 (mod p)
▪ We have 610 mod 11 = 1.
VIT/SCOPE/BCSE309-CNS/MODULE 1 67
Example 2
➢ Find the result of 312 mod 11.
➢ Solution
▪ Given: a=3; p=11
▪ Here the exponent (12) and the modulus (11) are not the
same.
▪ With substitution, this can be solved using Fermat’s little
theorem.
▪ 312 mod 11 = (311 × 3) mod 11 = (311 mod 11) (3 mod 11)
= (3 × 3) mod 11 = 9
VIT/SCOPE/BCSE309-CNS/MODULE 1 68
Multiplicative Inverses using Fermat’s Little
Theorem
➢ Euler’s theorem can be used to find multiplicative inverses modulo
a composite.
➢ If p is a prime and a is an integer, such that p does not divide a,
then
a−1 mod p = ap−2 mod p
➢ Proof
• a × a−1 mod p = a × ap−2 mod p (multiply both sides of the equation
by a)
• ap−1 mod p = 1 mod p (use the first version of Fermat’s Little
theorem)
VIT/SCOPE/BCSE309-CNS/MODULE 1 69
Example
➢ Find the multiplicative inverse of 8 in Z17
➢ Solution
▪ Given: a=8; n=17
▪ a and n are relatively prime. Using Fermat’s Little Theorem:
a-1 mod p= ap-2 (mod p)
8−1 mod 17 = 817−2 mod 17
= 815 mod 17
= 15 mod 17
The multiplicative inverse of 8 in Z17 is 15
VIT/SCOPE/BCSE309-CNS/MODULE 1 70
Practice
1. Using Fermat’s theorem, find 3201 mod 11
2. Find the multiplicative inverse of 60 in Z101
3. Find 5−1 mod 23
4. Find 22−1 mod 211
5. Using Fermat’s theorem to find a number a between 0
and 92 with a congruent to 71013 modulo 93
VIT/SCOPE/BCSE309-CNS/MODULE 1 71
Euler's Totient Function
➢ An important quantity in number theory is *Euler's Totient
Function:
▪ The number of positive integers less than n and relatively prime
to n.
➢ It is written as φ(n)
φ(1) = 1
φ( p ) = p − 1 (for p prime)
φ ( m) m − 1 (for m composite)
➢ In other words, Euler's Totient Function φ(n) is the number of
elements in Zn*
*Leonhard Euler (1707 - 1783), Swiss mathematician
VIT/SCOPE/BCSE309-CNS/MODULE 1 72
Example 1
➢ Determine φ(37) and φ(35)
➢ To determine φ(37)
▪ Because 37 is prime, all of the positive integers from 1 through 36
are relatively prime to 37.
▪ Thus φ(37)= 36
➢ To determine φ(35)
▪ List all positive integers less than 35 that are relatively prime to it.
▪ 1, 2, 3, 4, 6, 8, 9. 11, 12,13, 16, 17, 18, 19, 22, 23, 24, 26, 27, 29, 31,
32, 33, 34
▪ There are 24 numbers on list, so φ(35) = 24
VIT/SCOPE/BCSE309-CNS/MODULE 1 73
Some Values of Euler’s Totient Function
VIT/SCOPE/BCSE309-CNS/MODULE 1 74
Euler's Totient Function…
Properties
1. φ(1) = 1
2. φ(p) = p − 1 if p is a prime.
3. φ(m × n) = φ(m) × φ(n) if m and n are relatively prime
4. φ(pe) = pe − pe−1 if p is a prime.
VIT/SCOPE/BCSE309-CNS/MODULE 1 75
Euler's Totient Function…
➢ Proof for Property 3: Assume we have two distinct prime numbers, p
and q, and an integer n = pq
▪ Then: φ(n) = φ( pq) = φ( p) φ(q) = ( p − 1) (q − 1)
▪ The set of residues in Zn is {0,1,...,(pq - 1)}
▪ The residues that are not relatively prime to n are:
‧ The set {p, 2p, ... ,(q - 1)p}, the set {q, 2q, ... ,(p - 1)q}, and 0
So: φ(n) = pq − [(q − 1) + ( p − 1) + 1]
= pq − ( p + q ) + 1
= ( p − 1) (q − 1)
= φ( p ) φ( q )
VIT/SCOPE/BCSE309-CNS/MODULE 1 76
Example 2
➢ φ(21) = φ(3) × φ(7)
= (3-1) × (7-1)
= 2× 6 = 12
The 12 integers are {1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20}
VIT/SCOPE/BCSE309-CNS/MODULE 1 77
Practice
1. What is the number of elements in Z14*
2. What is the value of φ(240)?
VIT/SCOPE/BCSE309-CNS/MODULE 1 78
Euler’s Theorem
➢ Euler’s theorem is the generalization of Fermat’s Little theorem
➢ The modulus in the Fermat theorem is a prime, and the modulus
in Euler’s theorem is an integer
➢ Euler’s theorem states that for every a and n that are relatively
prime
aφ(n) 1 mod n
➢ Second Version: It removes the condition that a and n should be
coprime. If n = p × q, a < n, and k an integer, then
a k × φ(n)+1 a mod n
VIT/SCOPE/BCSE309-CNS/MODULE 1 79
Euler’s Theorem…
➢ Applications
▪ Helpful for quickly finding a solution to some
exponentiations
▪ Used to find multiplicative inverses
VIT/SCOPE/BCSE309-CNS/MODULE 1 80
Example
➢ Find the result of 624 mod 35
➢ Solution
▪ Given: a=6; n=35;
▪ Find gcd (35,6) =1. Hence, a and n are relatively prime
▪ φ(35)=24
▪ We have 624 mod 35= 6φ(35) mod 35
▪ Applying Euler’s theorem, 6φ(35) mod 35 = 1
VIT/SCOPE/BCSE309-CNS/MODULE 1 82
Practice
➢ Find the result of 2062 mod 77
➢ Solution
▪ Given a=20; n=77
▪ Find gcd(77,20)≠ 1
▪ n=p × q implies 77 = 7 × 11
▪ If we let k = 1 on the second version of Euler’s theorem
▪ 2062 mod 77= 20 1 ×φ(77)+1 mod 77
=[(20 mod 77) (20φ(77)+1 mod 77) ]mod 77
= (20)(20) mod 77 [since, 20φ(77)+1 mod 77 = 20(mod 77)]
= 400 (mod 77) =15
VIT/SCOPE/BCSE309-CNS/MODULE 1 83
Multiplicative Inverses using Euler Theorem
➢ Euler’s theorem can be used to find multiplicative inverses
modulo a composite.
➢ If n and a are coprime, then
a−1 mod n = aφ(n)−1 mod n
➢ Example
8−1 mod 77 = 8φ(77)−1 mod 77 [φ(77)=φ(7)×φ(11)=6×10=60]
= 859 mod 77
= 29 mod 77
VIT/SCOPE/BCSE309-CNS/MODULE 1 84
Practice
1) 7−1 mod 15
2) 71−1 mod 100
VIT/SCOPE/BCSE309-CNS/MODULE 1 85
Chinese Reminder Theorem (CRT)…
╸ Applications
➢ Solve system of congruences or quadratic congruence
➢ Represent a very large integer in terms of a list of small integers.
VIT/SCOPE/BCSE309-CNS/MODULE 1 86
CRT: Solving Congruences
1. Find M = m1 × m2 × … × mk. This is the common modulus.
2. Find M1 = M/m1, M2 = M/m2, …, Mk = M/mk
3. Find the multiplicative inverse of M1, M2, …, Mk using the
corresponding moduli (m1, m2, …, mk). Call the inverses M1 −1, M2
−1, …, M −1.
k
4. The solution to the simultaneous congruences is
x = (a1 × M1 × M1 −1 + a2 × M2 × M2 −1 + … + ak × Mk × Mk −1) mod M
VIT/SCOPE/BCSE309-CNS/MODULE 1 87
Example 1
➢ Find the solution to the simultaneous equations:
x ≡ 2 mod 3
x ≡ 3 mod 5
x ≡ 2 mod 7
VIT/SCOPE/BCSE309-CNS/MODULE 1 88
Example 1…
➢ Solution
1) M = 3 × 5 × 7 = 105
2) M1 = 105 / 3 = 35, M2 = 105 / 5 = 21, M3 = 105 / 7 = 15
3) The inverses are M1−1 = 2, M2 −1 = 1, and M3 −1 = 1
4) x = (2 × 35 × 2 + 3 × 21 × 1 + 2 × 15 × 1) mod 105 = 23
mod 105
VIT/SCOPE/BCSE309-CNS/MODULE 1 89
Example 2
➢ Find the solution to the simultaneous equations:
x 5 (mod 7)
x 3 (mod 11)
x 10 (mod 13)
VIT/SCOPE/BCSE309-CNS/MODULE 1 90
Example 2…
1. m1=7, m2=11, m3=13, M=1001
2. M1=1001/7=143, M2=1001/11=91, M3=1001/13=77
3. M1−1 =143-1 mod 7 = 3-1 mod 7 = 5
M2−1 =91-1 mod 11 = 3-1 mod 11 = 4
M3−1 =77-1 mod 13 = 12-1 mod 13 = 12
4. x = (5×143×5 + 3×91×4 + 10×77×12) mod 1001
= 13907 mod 1001 = 894mod 1001
VIT/SCOPE/BCSE309-CNS/MODULE 1 91
Practice
➢ Find an integer that has a remainder of 3 when divided by
7 and 13, but is divisible by 12
➢ Solution
▪ This is a CRT problem.
▪ We can form three equations and solve them to find the value
of x.
x = 3 mod 7
x = 3 mod 13
x = 0 mod 12
x = 276
VIT/SCOPE/BCSE309-CNS/MODULE 1 92
Example 3
➢ Represent 973 mod 1813 as a pair of numbers mod 37 and 49
➢ Solution
▪ Define m1 = 37 m2 = 49 ; M = 1813; x = 973
▪ Taking residues modulo 37 and 49, our representation of 973
is (11, 42), because 973 mod 37 = 11 and 973 mod 49 = 42.
VIT/SCOPE/BCSE309-CNS/MODULE 1 93
Discrete Logarithms
➢ The discrete logarithm problem is one of the most
important one-way functions in modern asymmetric
cryptography.
➢ Many public-key algorithms are based on it.
➢ Concepts
▪ Finite Multiplicative Group
▪ Order of the Group
▪ Order of an Element
▪ Primitive Roots
▪ Cyclic Group
VIT/SCOPE/BCSE309-CNS/MODULE 1 94
Group G
➢ A group is a monoid in which any element is invertible.
➢ A set of elements or “numbers” with some operation
whose result is also in the set (closure)
➢ Obeys:
▪ associative law:(a.b).c = a.(b.c)
▪ has identity e: e.a = a.e = a
▪ has inverses a-1: a.a-1 = e
Here, a, b and c are the elements of G
VIT/SCOPE/BCSE309-CNS/MODULE 1 95
Group..
➢ Abelian Group or Commutative Group
▪ The group is called commutative or abelian if the
monoid is commutative.
▪ That is, for all a and b in G, we have a.b = b.a
▪ The set of residue integers with the addition operator, G
= < Zn, +>, is a commutative group
▪ The set Zn* with the multiplication operator, G=< Zn*, ×>
, is an abelian group
VIT/SCOPE/BCSE309-CNS/MODULE 1 96
Finite Multiplicative Group
➢ Finite and Infinite Groups
▪ A group G is said to be finite if the number of elements
in the set G is finite. Otherwise, the group is infinite.
▪ The group G = < Zn*, ×> is a finite multiplicative group in
which the operation is multiplication.
▪ The set Zn* contains those integers from 1 to n-1 that are
relatively prime to n.
VIT/SCOPE/BCSE309-CNS/MODULE 1 97
Order of a group
➢ The order of a group, |G|, is the number of elements in
the group.
➢ In G = < Zn*, ×>, the order of the group is φ(n)
➢ Example: What is the order of the group G = < Z21*, ×>
|G|= φ(21)=φ(7) × φ(3)=12
VIT/SCOPE/BCSE309-CNS/MODULE 1 98
Order of an element
➢ The order of an element a in a group, ord(a), is the
smallest integer i such that ai ≡ e(mod n)
➢ The order of an element divides the order of the group
➢ Example: Find the order of all elements in G = < Z10*, ×>
▪ This group has φ(10)=4 elements
▪ The elements are: 1, 3, 7 and 9
▪ The orders of the elements are: ord(1) = 1, ord(3) = 4,
ord(7) = 4, ord(9) = 2.
VIT/SCOPE/BCSE309-CNS/MODULE 1 99
Primitive Root
➢ In G = < Zn*, ×>, when the order of the element is same as
φ(n), that element is called the primitive root of the
group.
➢ Example:Consider the group G = < Z7*, ×>
▪ The primitive roots of this group are 3 and 5
➢ G = < Zn*, ×> has primitive roots only if n is 2,4, pt or 2pt
➢ Note: P is an odd prime and t is an integer.
VIT/SCOPE/BCSE309-CNS/MODULE 1 100
Cyclic Group
➢ If the group G = < Zn*, ×> has primitive roots, it is cyclic
➢ Each primitive root is a generator and can be used to
create the whole set
➢ Example: G = < Z10*, ×>
▪ The elements are: 1, 3, 7 and 9
▪ Its primitive roots are 3 and 7
▪ When g=3, g1mod10=3; g2mod10=9; g3mod10=7;
g4mod10=1
▪ When g=7, all the elements can be generated
VIT/SCOPE/BCSE309-CNS/MODULE 1 101
Logarithms for Modular Arithmetic
➢ Exponentiation and logarithm are inverses of each other.
▪ Exponentiation: y = ax → Logarithm: x = logay
▪ a is called the base of the exponentiation or logarithm
➢Properties of logarithms
1) logx(1) = 0
2) logx (x) = 1
3) logx (yz) = logx (y) + logx (z)
4) logx (yr ) = r * logx (y)
VIT/SCOPE/BCSE309-CNS/MODULE 1 105
Solution to Modular Logarithm Using Discrete
Logs
To solve problems of type y = ax (mod n) when y is given,
and we need to find x.
1. Tabulation of Discrete Logarithms
2. Using Properties of Discrete Logarithms
10 11 12 13 14 15 16 17 18
17 15 11 3 6 12 5 10 1
VIT/SCOPE/BCSE309-CNS/MODULE 1 111
Using Properties of Discrete Logarithms
VIT/SCOPE/BCSE309-CNS/MODULE 1 114
Example 1
➢x5 ≡ 11 mod 17
➢Solution
▪ Find a primitive root in the group G = <Z17*, × >
▪ The first primitive root in this group is 3
▪ The discrete logarithm table for this root
VIT/SCOPE/BCSE309-CNS/MODULE 1 115
Example1…
▪ Solve the congruence equation 5 × L3(x) ≡ 7 (mod 16).
VIT/SCOPE/BCSE309-CNS/MODULE 1 116
Example 2
➢2x11 ≡ 22 mod 19 ≡ 3 mod 19
➢Solution
▪ Find a primitive root in the group G = <Z19*, × >
▪ The first primitive root in this group is 2
▪ The discrete logarithm table for this root
VIT/SCOPE/BCSE309-CNS/MODULE 1 117
Example 2…
▪ Solve the congruence equation 11 × L2(x) ≡ 12 (mod 18).
VIT/SCOPE/BCSE309-CNS/MODULE 1 118
Testing for Primality
always gives a correct answer
Deterministic
Examples: divisibility
algorithm, AKS algorithm
Algorithms
gives an answer that is
correct most of the time, but
not all of the time.
Probabilistic
Examples: Fermat Primality,
Square Root, Miller-Rabin
VIT/SCOPE/BCSE309-CNS/MODULE 1 119
Miller-Rabin Algorithm
▪ Typically used to test a large number for primality
▪ Algorithm is: TEST (n)
1. Find integers k, q, with k > 0, q odd, so that (n – 1)=2kq ;
4. for j = 0 to k – 1 do
6. return (“composite") ;
VIT/SCOPE/BCSE309-CNS/MODULE 1 122
Practice Questions
Find the results of the following:
1) 32023 mod 461
2) 173641 mod 2134
3) 200135 mod 2000
4) 515mod 13
5) 45617 mod 17
VIT/SCOPE/BCSE309-CNS/MODULE 1 123
Practice Questions
Find the results of the following:
1) 27-1 mod 41
2) 70-1 mod 101
3) 16-1 mod 323
4) 44-1 mod 667
VIT/SCOPE/BCSE309-CNS/MODULE 1 124
Practice Questions
1. Using the efficient algorithm, compute 13125 mod 15.
2. Use Euler’s theorem to find a number a between 0 and 8 such
that a is congruent to 9101 modulo 10.
3. Solve the congruence x103 ≡ 4 modulo 11.
VIT/SCOPE/BCSE309-CNS/MODULE 1 125
Practice Questions
1. Find all solutions x, if they exist, to the system of
equivalences:
2x ≡ 6 (mod 14)
3x ≡ 9 (mod 15)
5x ≡ 20 (mod 60)
2. Solve the simultaneous congruences
x ≡ 6 (mod 11), x ≡ 13 (mod 16), x ≡ 9 (mod 21),and
x ≡ 19 (mod 25)
VIT/SCOPE/BCSE309-CNS/MODULE 1 126