Cryptography and Network Security
Unit - 2
Advanced Encryption Standard
Topics
Introduction to Group, Field
Finite field of the form GF(p)
Modular Arithmetic
Prime and Relative Prime Numbers
Extended Euclidean Algorithm
Advanced Encryption Standard(AES) Encryption and Decryption
Fermat’s and Euler’s Theorem
Primality Testing
Chinese Remainder Theorem
Discrete Logarithmic Problem
Principals of Public key CryptoSystems
RSA Algorithm
Security of RSA
Group
A Group G, denoted by {G,*} is a set of elements with a binary operation
‘*’ that satisfies the following four properties:-
1. Closure:- c=a*b
2. Associativity:- (a*b)*c = a*(b*c)
3. Identity:- a*e = e*a=a
4. Inverse:- a*a’ = a’*a = e
Field
A Field F , denoted by {F,+,*} is a set of elements with two binary
operations, called addition and multiplication such that for all a,b,c in F
the following axioms are obeyed:
1. F is a integral domain.
2. Multiplicative Inverse:- For each a in F, except 0 there is an
element a -1 in F such that aa -1 = a-1 a = 1
GF(p) Fields:-
When n=1, we have GF(p) field. This field can be the set Zp , {0,1, .... , p-1},
with two arithmetic operations(addition and multiplication).
In this set each element has an additive inverse and that nonzero elements
have a multiplicative inverse (no multiplicative inverse for 0).
For example: A field GF(2) with the set(0,1) and two operations, addition and
multiplication is shown as:
Addition Multiplication
{0,1} + * + 0 1 * 0 1
0 0 1 0 0 0
GF(2)
1 1 0 1 0 1
Ring
A ring R, denoted by [R,+,x], is a set of elements with two binary
operations, called addition and multiplication, such that for all a, b, c in R
the following axioms are obeyed:
1. Closure under multiplication: If a and b belong to R, then ab is also in R.
2. Associativity of multiplication: a(bc)=(ab)c for all a, b, c in R.
3. Distributive laws: a(b+c)=ab+ac for all a, b, c in R
(a+b)c=ac+bc for all a, b, c in R
4. Commutative of multiplication: ab = ba for all a, b in R.
5. Multiplicative identity: There is an element 1 in R such that a1=1a for all
a in R.
6. No zero divisors: If a, b belong to R and ab=0. then either a=0 or b=0.
Modular Arithmetic
1. Modular arithmetic is a system of arithmetic for integers, where numbers
reduces to a certain value i.e., the modulus.
2. Modular arithmetic is used in number theory to calculate checksums and
identifiers to spot error.
3. Modular arithmetic is used to limit the size of integer coefficients in
intermediate calculation and data.
Prime Number
Relative Prime Number
Method for Calculating Relatively Prime Numbers Less Than a Given Number:
1. Prime Factorization:
Find the exponential prime factorization of the number.
2. Pair-wise Calculation:
For each term, derive two numbers:
Subtract 1 from the base for the first number.
Subtract 1 from the exponent and evaluate for the second number.
3. Multiplication:
Multiply all numbers obtained in step 2.
Extended Euclidean Algorithm
1. Definition: Extension of Euclidean algorithm.
2. Purpose: Finds gcd(x, y) and multiplicative inverses m, n.
Equation : mx+ny =gcd(x,y) where m is the inverse of x mod y and n is
the inverse of y mod x.
Algorithm Steps:
a := x
b := y
c := 1
d := 0
e := 0
f := 1
while (b > 0):
q := a / b
r := a - q * b
a := b
b := r
m := c - q * d
c:= d
d := m
n := e - q * f
e := f
f := n
gcd(x, y) := a
m := c
n := e
Advanced Encryption Standard
1. AES is a block cipher designed for commercial use, aiming to replace DES.
2. It operates on 128-bit blocks and supports key sizes of 128, 192, or 256 bits.
3. Unlike DES, AES does not use a Feistel structure.
4. Each AES round consists of four functions: byte substitution, permutation, finite
field arithmetic, and XOR with a key.
5. AES is a non-Feistel symmetric key algorithm.
6. It encrypts and decrypts 128-bit data blocks.
Functioning of AES:
1. Encryption process: In encryption process, each round comprise of four
sub-processes. The first round process is shown as:
1. SubBytes (Byte Substitution): Use an S-box to substitute each byte in the
block, storing the result in a 4x4 matrix.
2. ShiftRows : Shift each row of the matrix to the left, re-inserting any entries
that fall off on the right.
1. MixColumns (Not in Last Round) : Transform each column using a mathematical
function, creating a new matrix of 16 bytes.
2. AddRoundKey : XOR the matrix with the 128-bit round key. If it's the last round,
output the ciphertext; otherwise, proceed to the next round.
2. Decryption process: The process of decryption of an AES ciphertext is similar
to the encryption process in the reverse order. Each round consists of the four
processes conducted in the given order:
i. Add RoundKey
ii. MixColumns
iii. Shift Rows
iv. Byte substitution
Note: Encryption and decryption algorithms are separate due to the reverse
order of sub-processes in each round.
Advantages of DES
1. Works Everywhere: Strong in hardware, software.
2. Different Key Sizes: 128, 192, 256 bits.
3. Used Everywhere: Wireless, finance, storage.
4. Very Tough to Hack: 2^128 tries.
Disadvantages of DES
1. Simple Math Structure: Affects security.
2. Same Block Every Time: May show patterns.
3. Hard in Software: Tough to make.
4. Tricky Counter Mode: Software speed, safety.
Fermat’s Little Theorem
1. States if P is prime and a is an integer not divisible by P, then
a ≡
p-1
1(modP).
≡
2. If P is prime and a is an integer, then a p a(modP).
Proof:
Zpis the set of integers P tp (0,1,...,P−1). Multiplying these by a modulo P results in
the same set in some order.
≡
The product of these numbers modulo P is (P−1)! 1(modP).
≡
Therefore, a p-1 1(modP).
Euler’s Theorem
If a and n are coprime positive integers, then aϕ(n) ≡
1(modn), where ϕ(n) is
Euler's totient function, representing the count of positive integers less than n
that are coprime to n.
Proof:
1. Consider the set S={r1,r2,...,rϕ(n) } of all positive integers less than n and coprime
to n.
2. Multiply each element of S by a: a×r1,a×r2,...,a×rϕ(n) .
≡
3. These new elements are also coprime to n because if a×ri a×rj(mod n) for some
≡
i != j, then ri rj(mod n), which is not possible since riand rjare coprime to n.
4. The set S and its multiplied version cover all the positive integers less than n that
are coprime to n.
5. The product a×r1×a×r2×...×a×rϕ(n) is congruent to the product r1×r2×...×rϕ(n)
modulo n.
6.Cancel out the common factor a
ϕ(n) ϕ(n)
on both sides, leaving a ≡
×1
1(mod)a
ϕ(n)
×1 ≡
1(modn).
ϕ(n)
7. Thus, a ≡1(modn), proving Euler's Theorem.
Euler Totient Function
Euler's totient function, denoted as ϕ(n), represents the count of positive
integers smaller than n and relatively prime to n. The set of these numbers is
denoted as Zn .
Rules for Calculating ϕ(n):
1. Rule 1: ϕ(1)=1
2. Rule 2: ϕ(p)=p−1, if p is a prime number.
3. Rule 3: ϕ(m n )=ϕ(m)×ϕ(n), if m and n are relatively prime.
4. Rule 4: ϕ(pe )=pe − p e-1, if p is prime.
To compute ϕ(n), consider two distinct prime numbers p and q such that n=pq:
⇒ ⇒
ϕ(n)=ϕ(pq) ϕ(p)×ϕ(q) (p−1)×(q−1)
Primality Testing
Primality testing is used to check whether a given large number is prime or composite.
Algorithm Categories:
a. Deterministic Algorithms:
i. Basic Algorithm: Divides p by all values from 2 to √pto check for divisibility.
ii. Divisibility Algorithm: Tests divisibility up to √psince factors must be ≤√p.
b. Probabilistic Algorithms:
i. Fermat's Primality Test: Probabilistic, checks if a ≡
p-1
1 modp for a random a.
ii. Miller-Rabin Test: Another probabilistic test; returns composite if not prime, or
inconclusive.
Miller-Rabin Algorithm
Purpose: Used for primality testing of large numbers.
Efficiency:
3
Polynomial-time algorithm with a run-time complexity of O((logn) ).
Key Properties:
Utilizes two basic properties of prime numbers.
≡
If p is prime and 1<x<p, then x 2 1 modp if and only if x modp=1 or x
modp = −1.
Prime Number Decomposition:
If p is a prime number greater than 2, then p−1=2 kq where k>0 and q is
odd.
Additional Property:
≡
q
For any positive integer x coprime to p, x 1 modp or x
q
≡ 1(mod p).
Pseudo code for Miller Rabin Primality Testing
MillerRabin(BigInteger n, int s): //return "true" or "false"
BigInteger a; // test whether n is prime;
for (int i = 1; i <= s; ++i){ // if it returns "false", then n is not
a = Random (2, n-1); prime;
if Witness (a, n) return false; // if it returns "true", then n is prime;
} // with probability atleast 1-2** (-8).
return true; // s is number of tests we want to
} perform on n.
Chinese Remainder Theorem
The Chinese Remainder Theorem (CRT) is used to solve a set of congruent
equations with one variable but different moduli, which are relatively prime.
1.Given Congruence Equations:
≡
x a1(modm 1)
≡
x a2(modm 2)
:
:
≡
x ak(modmk )
2. Conditions for CRT:
The moduli m1,m2,…,mkmust be pairwise relatively prime (i.e.,
gcd(m i ,mj )=1 for i≠j).
Numericals
1.By using CRT solve the simultaneous congruence X=2 modP for all P ∈ (3,5,7).
solving simultaneous congruence for X=2 modP for all P ∈ {3,5,7}.
X ≡ 2 mod P for all P ∈ {3,5,7}
X ≡ 2 mod 3
X ≡ 2 mod 5
X ≡ 2 mod 7
Step 1: M = 3 × 5 × 7 = 105
Step 2: M 1 = 105/3 = 35
M2 = 105/5 = 21
M3 = 105/7 = 15
-1
Step 3: M 1 = (35 × x)mod 2= 1
-1
M2 = (21 × x)mod 2= 1
-1
M3 = (15 × x)mod 2= 1
Step 4: X = (2 × 35 × 1 + 2 × 21 × 1 + 2 × 15 × 1)mod 105
=(70 + 42 + 30)mod 105 = (142)mod 105 = 37
2. Find the values of x for the following sets of Congruence using the
Chinese Remainder Theorem.
X = 2 mod 7 and X = 3 mod 9
Solution: X = 2 mod 7
X = 3 mod 9
M = m1 × m 2
= 7×9 = 63
M1 = 63/7=9
M2 = 63/9 = 7
-1
M 1 = 9-1 mod 7
9ϕ(7)-1 mod 7
9 2-1 mod 7 = 9 mod 7 = 2
M-1
2
= 7 -1 mod 9
= 7ϕ(9)-1 mod 9
=7 3-1 mod 9
2
= 7 mod 9
= 49 mod 9
=4
-1 -1
X = (a 1 × M1 ×M1 + a2 × M2 × M2 ) mod 63
X = (2×9×2 + 3×7×4) mod 63
X = 120 mod 63
X = 57
Discrete Logarithmic Problems
Discrete logarithms are the set of congruence classes (1,.... ,p-1) under
multiplication modulo, the prime p.
Finite Cyclic Group:
G is a cyclic group with n elements, written multiplicatively.
Representation of Elements:
Any g in G is expressed as g=b k , k an integer.
Congruence Modulo n:
Different k representing the same g are congruent modulo n.
Discrete Logarithm Function:
logb :G→Z n assigns congruence classes to g.
Group Isomorphism:
Discrete logarithm function is a group isomorphism, preserving
group structure.
Principle of Public key Cryptosystem
Public-key crypto addresses symmetric encryption challenges.
Symmetric issues:
(1) Requires shared pre-distributed keys,
(2) Dependence on key distribution centers.
Public-key solution eliminates these challenges.
Uses asymmetric key pairs: Public key shared, private key secret.
Core principle: Preserving total communication secrecy.
Application of Public Key Cryptosystem
1. Encryption/Decryption
2. Digital signature
3. Key Exchange
RSA Algorithm
RSA is a public key encryption algorithm, named for its inventors (Rivest,
Shamir and Adleman).
The RSA algorithms is based on the mathematical part that it is easy to find
and multiply large prime numbers together, but it is extremely difficult to
factor their product.
Key Generation:
1. Select two prime numbers p and q such that p≠q
2. Calculate n = p × q
3. Calculate ϕ(n) = (p-1)(q-1)
4. Select integer e such that gcd(ϕ(n),e) = 1; 1<e<ϕ(n)
-1
5. Calculated d = e (mod ϕ(n))
6. Public key PU = {e, n}
7. Private key PR = {d, n}
Encryption:
Calculate ciphertext C = Me modn
Decryption:
d
Calculate plaintext M = C modn
RSA Algorithm
1. Asymmetric Key Cryptography:
RSA is an asymmetric key cryptographic algorithm.
2. Mathematical Basis:
Relies on the ease of finding and multiplying large prime numbers but the
difficulty of factoring their product.
3. Key Sizes:
Private and public keys consist of 100 or more digits prime numbers.
4. Key Generation Challenge:
The primary challenge lies in selecting and generating the public and
private keys.
Algorithm Steps:
a. Choose large prime numbers p and q.
b. Calculate n=p×q.
c. Select the public key e (encryption key) such that it's not a factor of (p−1)
and (q−1).
d. Select the private key d (decryption key) satisfying (d×e)mod((p−1)×(q−1))=1.
Encryption:
Calculate ciphertext C=Me modn.
Send C as the ciphertext to the receiver.
Decryption:
d
Calculate plaintext M=C modn.
Numericals
1. In RSA, given e = 07 and n =3. Encrypt the message “ME” using 00 to 25
for letters A to Z.
Solution: Translate the numbers into letters: M=12 and E=4
Encrypt each block M using, C = M7 (mod 3)
For M = 12
7
C = 12 (mod 3)
4
= 12 × 123 (mod 3)
2 2
= (12 ) × 12 2 × 12(mod 3)
=0
For E = 4
7
C = E (mod 3)
7
= 4 (mod 3)
= 4 (mod 3)
= 1
The encrypted ciphertext is : 0 and 1
2. Perform encryption and decryption using RSA algorithm for p = 11, q= 13,e = 7,m=9.
Solution: Step 1: p = 11, q = 13
Step 2: n = p × q = 11 × 13 = 143
Step 3: Calculate
ϕ(n) = (p-1)(q-1)
= (11 - 1)(13 - 1) = 10 × 12 = 120
Step 4: Determine such that de = 1(mod 120)
d = e -1 mod 120
Using extended Euclidean algorithm we calculate d.
Note: t = t1-q*t2
= -17 mod 120
d = 103
Public key = {7,143}
Private key = {103,143}
Encryption(C) = Me(mod n)
M=9
7
C = 9 mod 143
2 1
= [( 94 mod 143) × (9 mod 143) × (9 mod 143)]mod 143
= (126 × 81 × 9) mod 143
= 91854 mod 143
= 48
103
Decryption (M) = 13 mod 143
3. Perform encryption and decryption using RSA algorithm for p = 17, q= 11,e = 7,m=88.
Solution: Step 1: p = 17, q = 11
Step 2: n = p × q = 17 × 11 = 187
Step 3: Calculate
ϕ(n) = (p-1)(q-1)
= (17 - 1)(11 - 1) = 16 × 10 = 160
Step 4: Determine d such that de = 1(mod 160)
d = e -1 mod 160 taking e = 7
Using extended Euclidean algorithm we calculate d.
d = 23
Public key = {7,187}
Private key = {23,187}
Encryption(C) = M e (mod n)
M = 88
C = 887 mod 187
4 2 1
= [( 88 mod 187) × (88 mod 187) × (88 mod 187)]mod 187
= (132 × 77 × 88) mod 187 = 11
23
Decryption (M) = 11 mod 187
1 2 4
= [( 11 mod 187) × (11 mod 187) × (11 mod 187) × (118 mod 187)
8
× (11 mod 187)]mod 187
= (11 × 121 × 55 × 33 × 33) mod 187 = 88
4. Let p = 17, q = 11, e = 7 and d = 23. Calculate the public key and private key and
show encryption and decryption for plain text M = 88 by using RSA algorithm.
Solution: Step 1: p = 17, q= 11
Step 2 : n = p × q = 17 × 11 = 187
Step 3: Calculate ϕ(n) = (p-1)(q-1)= 16 × 10 = 160
Step 4: d = 23 and e = 7
Public key is {7,187}
Private key is {23,187}
Encryption: Ciphertext is
C = M emod n = 88 7 mod 187 = (882 mod 187)(88 5 mod 187)
= [77 × (77 × 77) × 88] mod 187 = 11
C = 11
Decryption: Plaintext is
M = Cd mod n = 1123 mod 187 = (115 mod 187)(1118 mod 187)
= [44 × (44 × 44 × 44)(11 3 mod 187)] mod 187
= [444 × 22] mod 187 = 88
Advantages of RSA Algorithm
1. Convenience in Key Distribution.
2. Provides Message Authentication.
3. Detection of Tampering.
4. Offers Non-Repudiation.
Disadvantages of RSA Algorithm
1. Public Key Authentication.
2. Slow compared to Symmetric.
3. Higher Resource Usage.
4. Security Compromise Risks.
5. Irreparable Loss of Private Key.
Securities of RSA
1. Brute Force:
Approach: Trying all possible private keys.
Security Measure: Use a large key space.
2. Mathematical Attacks (Factoring):
Approach: Factoring the product of two primes.
Security Measure: Evaluate RSA security based on factoring
performance.
3. Timing Attacks:
Approach: Exploiting decryption algorithm running time.
Counter measures:
a. Constant Exponentiation Time: All exponentiations take the same
time, degrading performance.
b. Random Delay: Add random delay to confuse timing attacks.
c. Blinding: Multiply ciphertext by a random number before
exponentiation to prevent bit-by-bit analysis in timing attacks.
Previous Year Questions
2 Marks
1. Apply the Caesar Cipher(p=D(3,C)) and Decrypt the cipher text “PHHW PH”.
(2022-23)
2. Calculate Φ(35). (2022-23)
3. Find the value of ɸ(12).(2021-22)
4. Compute 361 mod 7. (2021-22)
10 Marks
1. What do you understand by Chinese Remainder Theorem? Solve the
following congruent equations by Chinese remainder theorem:
≡
i. X 2 mod 3
≡
ii. X 3 mod 5
≡
iii. X 2 mod 7 (2022-23)
2. Explain AES algorithm. What is the difference between the AES
encryption algorithm and the DES algorithm. (2022-23)
3. State and prove Fermat’s theorem. Use Fermat theorem to find a number
≡
‘a’ between 0 and 72 with a 9794 mod 73. (2022-23)
4.In a public key system using RSA, you intercept the cipher text C=8 sent to
a user whose public key is e=13, n=33. What is the plain text M? (2021-22)
5. Explain Chinese Remainder Theorem (CRT) and find X for the given set of
congruent equations using Chinese Remainder theorem : (2021-22)
X=1 mod 5
X=2 mod 7
X=3 mod 9
X=4 mod 11
6. Define Euler’s Totient Function. Prove that, ɸ(pq) = (p-1)(q-1), where p
and q are prime numbers. (2021-22)
7. Write the pseudo code for Miller Rabin primality testing. Test whether 61
is prime or not using the same Miller Rabin test . (2021-22)
8. Define a Group and Ring. Prove that the order of any subgroup of finite
group divides the order of the group. (2021-22)
THANK YOU
LIKE &
SO MUCH!
SUBSCRIBE