0% found this document useful (0 votes)
14 views46 pages

Lec 2

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)
14 views46 pages

Lec 2

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/ 46

Department of Information Security (IS),

Military College of Signals (MCS), NUST


Course : Advanced Cryptography – I (IS-842)
Lecture Hours : 3/week

Text Book : 1. Cryptography: An Introduction by Nigel Smart


2. Understanding Cryptography by Christof Paar and Jan
Pelzl
3. Cryptography And Network Security Principles and
Practice by William Stallings
4. Introduction To Cryptography And Network Security
by Behrouz A. Forouzan

Instructor : Dr. Faiz Ul Islam


(BS-UET Pesh-2013, MS & PhD - NJUST, China-2014-23)
: [email protected]
Introduction to Cryptography
GCD & Relatively Prime Numbers
Euclidean Algorithm
Extended Euclidean Algorithm (EEA)
Congruence
Residue Class
Operations in Zn
Arithmetic Tables
Common divisor
GCD & Relatively Prime Numbers

GCD
❑ The greatest common divisor (GCD) of two positive integers is
the largest integer that can divide both integers.
❑ The divisors of 30 are 1, 2, 3, 5, 6, 10, 15, 30
❑ The common divisors of 12 and 30 are 1, 2, 3, 6.
❑ GCD(12,30) = 6.
❑ When gcd (a, b) = 1, we say that a and b are relatively prime.
Introduction to Cryptography
GCD & Relatively Prime Numbers
Euclidean Algorithm
Extended Euclidean Algorithm (EEA)
Congruence
Residue Class
Operations in Zn
Arithmetic Tables
Why Euclidean Algorithm??
gcd (748, 2024) = 44

2000 years ago a mathematician named Euclid developed an algorithm


that can find the gcd of two positive integers.
Euclidean Algorithm

An efficient way to find the gcd (a, b), uses facts that:
❑ Fact1: gcd (a, 0) = a
❑ Fact2: gcd (a, b) = gcd (b, r)
where r is the remainder of dividing a by b
❑ gcd(a, b) = gcd(b, a mod b) r is replaced by a mod b
Euclidean Algorithm (Algo)

❑ gcd(a, b)
❑ Euclidean Algorithm to compute gcd(a, b) is:
Euclid(a, b)
if (b = 0) then return a;
else return Euclid(b, a mod b);
Euclidean Algorithm

gcd (36, 10) = gcd (10, 6) = gcd (6, 4) = gcd (4, 2) = gcd (2, 0) = 2
q r1 r2 r
36/10= 10*3+6 1 2740 1760 980
R=6, hence b=10, 1 1760 980 780
r=6 1 980 780 200
3 780 200 180
1 200 180 20
9 180 20 0
Find the greatest common
x 20 0 x
divisor of 2740 and 1760.
Introduction to Cryptography
Find the greatest common divisor of 25 and 60?

gcd (25, 65) = 5


Euclidean Algorithm (process & Algo)
Introduction to Cryptography
GCD & Relatively Prime Numbers
Euclidean Algorithm
Extended Euclidean Algorithm (EEA)
Congruence
Residue Class
Operations in Zn
Arithmetic Tables
The Extended Euclidean Algorithm

❑ An extension of the algorithm allows us to compute modular inverses, which is


of major importance in public-key cryptography
Let a and b be positive integers. Then the equation

gcd(a, b) = as + bt
where s and t are integer coefficients, this equation is often referred to as
Diophantine equation

The question now is: how do we compute the two coefficients s and t?

r = r1 − q × r2, s = s1 − q × s2, t = t1 − q × t2
The Extended Euclidean Algorithm (EEA)

Ex: Given a = 161 and b = 28, find gcd (a, b) and the values of s and t.

❑ The calculations of r, s, and t are similar


❑Initial conditions (s1, s2, t1, t2) = (1, 0, 0, 1)
❑ r = r1 − q × r2, s = s1 − q × s2, t = t1 − q × t2
The Extended Euclidean Algorithm (EEA)

Ex: Given a = 161 and b = 28, find gcd (a, b) and the values of s and t.

gcd (161, 28) = 7, s = -1, t = 6, Lets test the answer


Home Task: Using the Extended Euclidean Algorithm (EEA), find the
inverse of two large numbers that are relatively prime
Extended Euclidean Algorithm (process)
Extended Euclidean Algorithm (Algo)
Home Task
1. Given a = 161 and b = 28, find gcd (a, b) and the values
of s and t. Also calculate the inverse.
2. Given a = 17 and b = 0, find gcd (a, b) and the values of
s and t. Also calculate the inverse.
3. Given a = 0 and b = 45, find gcd (a, b) and the values of
s and t. Also calculate the inverse.

Note: Min Group Members: 4


Introduction to Cryptography
GCD & Relatively Prime Numbers
Euclidean Algorithm
Extended Euclidean Algorithm (EEA)
Congruence
Residue Class
Operations in Zn
Arithmetic Tables
Congruence
“The theory of congruences is a powerful method in number theory
that is based on the simple idea of clock arithmetic”

Two integers are congruent if their mod(n) gives the same result
❑ Congruence operator ( ≡ )
2 ≡ 12 (mod 10) 13 ≡ 23 (mod 10)
34 ≡ 24 (mod 10) -8 ≡ 12 (mod 10)

Hints: “2 and 12 congruent modulo 10” or “x is


congruent to y modulo m”
“iff m divides a-b”
Congruence
Introduction to Cryptography
GCD & Relatively Prime Numbers
Euclidean Algorithm
Extended Euclidean Algorithm (EEA)
Congruence
Residue Class
Operations in Zn
Arithmetic Tables
Residue Class/equiv classes
Def: A residue class [a] or [a]n is the set of integers congruent modulo n
Or
It is the set of all integers such that x = a (mod n)
Ex: if n = 5, we have five sets [0], [1], [2], [3], and [4] as shown below:
Comparison of Z and Zn using graphs
Introduction to Cryptography
GCD & Relatively Prime Numbers
Euclidean Algorithm
Extended Euclidean Algorithm (EEA)
Congruence
Residue Class
Operations in Zn
Arithmetic Tables
Operations in Zn
❑ Binary operations for the set Z can also be defined for the set Zn
❑ The result may need to be mapped to Zn using the mod operator
Examples
Perform the following operations (the inputs come from Zn):
a. Add 7 to 14 in Z15
b. Subtract 11 from 7 in Z13
c. Multiply 11 by 7 in Z20

(14 + 7) mod 15 → (21) mod 15 = 6


(7 − 11) mod 13 → (−4) mod 13 = 9
(7 × 11) mod 20 → (77) mod 20 = 17
Self practice…

Perform the following operations (the inputs come from


either Z or Zn):
a. Add 17 to 27 in Z14
b. Subtract 34 from 12 in Z13
c. Multiply 123 by −10 in Z19
Properties

If a = 17, b = 27, n = 14, using (a+b) mod n;


(17 + 27) mod 14 → (44) mod 14 = 2
Now using (a + b) mod n = [(a mod n) + (b mod n) mod n]
Find the solution for a = 17 , b = 27, & n = 14.
Properties
Inverse

❑ In modular arithmetic, we often need to find the


inverse of a number relative to an operation
❑ Additive inverse (relative to an addition operation)
❑ Multiplicative inverse (relative to a multiplication
operation)
Additive Inverse
In Zn, two numbers a and b are additive inverses of each other if
❑ a + b ≡ 0 (mod n)
❑ In modular arithmetic, each integer has an additive inverse
❑ The sum of an integer and its additive inverse is congruent to
0 modulo n
❑ Six pairs of additive inverses pairs in Z10 are
(0, 0), (1, 9), (2, 8), (3, 7), (4, 6), and (5, 5)
Multiplicative Inverse
❑ In Zn, two numbers a and b are the multiplicative inverse of
each other if
a × b ≡ 1 (mod n)
❑ In modular arithmetic, an integer may or may not have a
multiplicative inverse
❑ The product of an integer and its multiplicative inverse is
congruent to 1 modulo n
❑ For example, if the modulus is 10, then the multiplicative
inverse of 3 is 7
❑ In other words, we have (3 × 7) mod 10 = 1
Multiplicative Inverse
❑ It can be proved that a has a multiplicative inverse in
Zn
Iff gcd (n, a) = 1
❑ In this case, a and n are said to be relatively prime
❑ (1, 1), (3, 7) and (9, 9) pairs have multiplicative inverse
in Z10
❑ 0, 2, 4, 5, 6, and 8 do not have a multiplicative inverse
Example
❑Find the multiplicative inverse of 8 in Z10.
❖ There is no multiplicative inverse because gcd (10, 8) = 2 ≠ 1
❖ In other words, we cannot find any number between 0 and 9 such that
when multiplied by 8, the result is congruent to 1

Home Task : Using the extended Euclidean algorithm, find the


multiplicative inverse of 11 in Z26
Introduction to Cryptography
GCD & Relatively Prime Numbers
Euclidean Algorithm
Extended Euclidean Algorithm (EEA)
Congruence
Residue Class
Operations in Zn
Arithmetic Tables
Addition modulo 8
Multiplication modulo 8
Notations
When required
❑Additive Inverse Zn
❑Multiplicative Inverse Zn*
Z6 = {0,1,2,3,4,5} Z6* = {1, 5}
Note: Multiplicative inverse of a number exists, if the
number is relatively prime wrt to n (modulo n)
Notations

Cryptography uses Zp and Zp* with the modulus as a prime


number p
Z7 = {0,1,2,3,4,5,6} Z7* = {1,2,3,4,5,6}
Notations

Cryptography uses Zp and Zp* with the modulus as a prime


number p
Z7 = {0,1,2,3,4,5,6} Z7* = {1,2,3,4,5,6}
Abstract Algebra

❑ Groups, rings, and fields are the fundamental elements


of a branch of mathematics known as abstract algebra,
or modern algebra
❑ In abstract algebra, we are concerned with sets on
whose elements we can operate algebraically; that is, we
can combine two elements of the set, perhaps in several
ways, to obtain a third element of the set
Abstract Algebra
Prepare

Finite (Galois) Fields


Activity (Upcoming week)
G-2 ppt???
Group Members
1. Muhammad Muneeb
2. Sibghatullah
3. Shahzad
4. Zeeshan

Topics: Encryption of the plaintext “Behappyman” using an affine


cipher with encryption key (3,7).

Note: Timing: 10-15 min, Group members: min 1 & max 4.

You might also like