Unit 2 NSC
Unit 2 NSC
PROFESSIONAL ELECTIVE
(L-2 T-1 C-3)
Unit -2
Prepared by
Dr. B. Umamageswari, AP/CTECH
Unit - 2
Algebraic structures, Divisibility and division algorithm, Euclidean algorithm,
Modular arithmetic, Prime numbers- Fermats and Eulers theorem,
Congruence and matrices, Block Ciphers and operations-Simplified Data
Encryption Standard - Data Encryption Standard - Advanced Encryption
Standard
Divisors
say a non-zero number b divides a if for
some m have a=mb (a,b,m all integers)
that is b divides into a with no remainder
denote this as b|a (“b divides a”)
and say that b is a divisor of a
eg. all of 1,2,3,4,6,8,12,24 divide 24
eg. 13 | 182; –5 | 30; 17 | 289; –3 | 33; 17 | 0
Properties of Divisibility
If a|1, then a = ±1.
If a|b and b|a, then a = ±b.
Any b /= 0 divides 0.
If a | b and b | c, then a | c
● e.g. 11 | 66 and 66 | 198 so 11 | 198
If b|g and b|h, then b|(mg + nh)
linear combinations for arbitrary integers m and n
e.g. b = 7; g = 14; h = 63; m = 3; n = 2
7|14 and 7|63 hence 7 | 168 (= 42 + 126)
Division Algorithm
if we divide a by n we get integer quotient
q and integer remainder r such that:
● a = qn + r where 0 <= r < n; q = floor(a/n)
remainder r often referred to as a residue
Greatest Common Divisor (GCD)
a common problem in number theory
GCD (a,b) of a and b is the largest integer
that divides evenly into both a and b
● e.g. GCD(60,24) = 12
define gcd(0, 0) = 0
often want no common factors (except 1)
define such numbers as relatively prime
● e.g. GCD(8,15) = 1
● hence 8 & 15 are relatively prime
Euclid’s algorithm to compute GCD
• Suppose we wish to determine the greatest common divisor d of the integers a and b;
that is determine d = gcd(a, b). Because gcd(|a|, |b|) = gcd(a, b), there is no harm in
assuming a >= b > 0.
• Dividing a by b and applying the division algorithm, we can state:
a = q1b + r1 where r1>=0 and r1<b
• First consider the case in which r1 = 0. Therefore, b divides a and clearly no larger
number divides both b and a, because that number would be larger than b. So, we have
d = gcd(a, b) = b.
The other possibility from Equation (2.2) is r1 ≠ 0. For this case, we can state that d|r1.
This is due to the basic properties of divisibility: the relations d|a and d|b together imply
that d (a - q1b), which is the same as d r1.
Euclid’s algorithm
Example GCD(1970,1066)
1970 = 1 x 1066 + 904 gcd(1066, 904)
1066 = 1 x 904 + 162 gcd(904, 162)
904 = 5 x 162 + 94 gcd(162, 94)
162 = 1 x 94 + 68 gcd(94, 68)
94 = 1 x 68 + 26 gcd(68, 26)
68 = 2 x 26 + 16 gcd(26, 16)
26 = 1 x 16 + 10 gcd(16, 10)
16 = 1 x 10 + 6 gcd(10, 6)
10 = 1 x 6 + 4 gcd(6, 4)
6 = 1 x 4 + 2 gcd(4, 2)
4 = 2 x 2 + 0 gcd(2, 0)
GCD(1160718174, 316258250)
Dividend Divisor Quotient Remainder
a = 1160718174 b = 316258250 q1 = 3 r1 = 211943424
b = 316258250 r1 = 211943424 q2 = 1 r2 = 104314826
r1 = 211943424 r2 = 104314826 q3 = 2 r3 = 3313772
r2 = 104314826 r3 = 3313772 q4 = 31 r4 = 1587894
r3 = 3313772 r4 = 1587894 q5 = 2 r5 = 137984
r4 = 1587894 r5 = 137984 q6 = 11 r6 = 70070
r5 = 137984 r6 = 70070 q7 = 1 r7 = 67914
r6 = 70070 r7 = 67914 q8 = 1 r8 = 2156
r7 = 67914 r8 = 2156 q9 = 31 r9 = 1078
r8 = 2156 r9 = 1078 q10 = 2 r10 = 0
Modular Arithmetic
define modulo operator “a mod n” to be
remainder when a is divided by n
● where integer n is called the modulus
b is called a residue of a mod n
● since with integers can always write: a = qn + b
● usually chose smallest positive remainder as residue
•ie. 0 <= b <= n-1
● process is known as modulo reduction
•eg. -12 mod 7 = -5 mod 7 = 2 mod 7 = 9 mod 7
a & b are congruent if: a mod n = b mod n
● when divided by n, a & b have same remainder
● eg. 100 mod 11 = 34 mod 11
so 100 is congruent to 34 mod 11
Modular Arithmetic Operations
can perform arithmetic with residues
uses a finite number of values, and loops
back from either end
Zn = {0, 1, . . . , (n – 1)}
modular arithmetic is when do addition &
multiplication and modulo reduce answer
can do reduction at any point, i.e.
a+b mod n = [a mod n + b mod n] mod n
Modular Arithmetic Operations
1. [(a mod n) + (b mod n)] mod n
= (a + b) mod n
2. [(a mod n) – (b mod n)] mod n
= (a – b) mod n
3. [(a mod n) x (b mod n)] mod n
= (a x b) mod n
e.g.
[(11 mod 8) + (15 mod 8)] mod 8 = 10 mod 8 = 2 (11 + 15) mod 8 = 26 mod 8 = 2
[(11 mod 8) – (15 mod 8)] mod 8 = –4 mod 8 = 4 (11 – 15) mod 8 = –4 mod 8 = 4
[(11 mod 8) x (15 mod 8)] mod 8 = 21 mod 8 = 5 (11 x 15) mod 8 = 165 mod 8 = 5
Modulo 8 Addition Example
+ 0 1 2 3 4 5 6 7
0 0 1 2 3 4 5 6 7
1 1 2 3 4 5 6 7 0
2 2 3 4 5 6 7 0 1
3 3 4 5 6 7 0 1 2
4 4 5 6 7 0 1 2 3
5 5 6 7 0 1 2 3 4
6 6 7 0 1 2 3 4 5
7 7 0 1 2 3 4 5 6
Modulo 8 Multiplication
+ 0 1 2 3 4 5 6 7
0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7
2 0 2 4 6 0 2 4 6
3 0 3 6 1 4 7 2 5
4 0 4 0 4 0 4 0 4
5 0 5 2 7 4 1 6 3
6 0 6 4 2 0 6 4 2
7 0 7 6 5 4 3 2 1
Modular Arithmetic Properties
Refer word docx for proof
-111(1759) + 355(550) = 1
Prime Numbers
prime numbers only have divisors of 1 and self
● they cannot be written as a product of other numbers
● note: 1 is prime, but is generally not of interest
eg. 2,3,5,7 are prime, 4,6,8,9,10 are not
prime numbers are central to number theory
list of prime number less than 200 is:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179
181 191 193 197 199
Prime Factorization
to factor a number n is to write it as a
product of other numbers: n=a x b x c
note that factoring a number is relatively
hard compared to multiplying the factors
together to generate the number
Fundamental theorem of arithmetic
the prime factorization of a number n is
when its written as a product of primes
● eg. 91=7x13 ; 3600=24x32x52
Relatively Prime Numbers & GCD
two numbers a, b are relatively prime if have
no common divisors apart from 1 also called as co prime
● eg. 8 & 15 are relatively prime since factors of 8 are
1,2,4,8 and of 15 are 1,3,5,15 and 1 is the only
common factor
conversely can determine the greatest common
divisor by comparing their prime factorizations
and using least powers
● eg. 300=21x31x52 18=21x32 hence
GCD(18,300)=21x31x50=6
Fermat's Theorem
ap-1 = 1 (mod p)
● where p is prime and gcd(a,p)=1
also known as Fermat’s Little Theorem
also have: ap = a (mod p)
useful in public key and primality testing
Euler Totient Function ø(n)
when doing arithmetic modulo n
complete set of residues is: 0..n-1
reduced set of residues is those numbers
(residues) which are relatively prime to n
● eg for n=10,
● complete set of residues is {0,1,2,3,4,5,6,7,8,9}
● reduced set of residues is {1,3,7,9}
number of elements in reduced set of residues is
called the Euler Totient Function ø(n)
Euler Totient Function ø(n)
to compute ø(n) need to count number of
residues to be excluded
in general need prime factorization, but
● for p (p prime) ø(p)=p-1
● for p.q (p,q prime) ø(p.q)=(p-1)x(q-1)
eg.
ø(37) = 36
ø(21) = (3–1)x(7–1) = 2x6 = 12
Euler's Theorem
First chk if a, n are relatively prime to each other
Block Cipher
Block Size - 64 bits, 128 bits
Simple
Confusion and Diffusion
Slower
Electronic Code Book (ECB) and
Cipher Block Chaining (CBC)
Reverse of encryption
DES, AES
Block Cipher Principles
most symmetric block ciphers are based on a
Feistel Cipher Structure
needed since must be able to decrypt ciphertext
to recover messages efficiently
block ciphers look like an extremely large
substitution
would need table of 264 entries for a 64-bit block
instead create from smaller building blocks
using idea of a product cipher
Ideal Block Cipher
permutation
Claude Shannon and
Substitution-Permutation Ciphers
Claude Shannon introduced idea of
substitution-permutation (S-P) networks in 1949
paper
form basis of modern block ciphers
S-P nets are based on the two primitive
cryptographic operations seen before:
● substitution (S-box)
● permutation (P-box)
provide confusion & diffusion of message & key
Confusion and Diffusion
cipher needs to completely obscure
statistical properties of original message
a one-time pad does this
more practically Shannon suggested
combining S & P elements to obtain:
diffusion – dissipates statistical structure
of plaintext over bulk of ciphertext
confusion – makes relationship between
ciphertext and key as complex as possible
Feistel Cipher Structure
Horst Feistel devised the Feistel cipher
● based on concept of invertible product cipher
partitions input block into two halves
● process through multiple rounds which
● perform a substitution on left data half
● based on round function of right half & subkey
● then have permutation swapping halves
implements Shannon’s S-P net concept
Feistel Cipher Structure
Feistel Cipher Structure
Feistel Cipher Design Elements
Key size and the number of rounds are critical factors in encryption
security. Larger keys enhance security but may slow down the
encryption and decryption process.
Collapse
block size 09:39
A larger key size increases security but can reduce the speed of
encryption and decryption, which is crucial for efficient data transfer.
key size 10:26
Having only one round in the encryption process is inadequate for
security, necessitating multiple rounds for effective encryption and
subkey generation algorithm and decryption, emphasizing the importance of the order of key usage.
11:40
The design of secure encryption algorithms requires complexity in key
generation and round functions to resist cryptanalysis. Additionally,
round function speed and ease of analysis are crucial for practical applications.
Collapse
11:42
fast software en/decryption A complex key size is vital for enhancing security, making it difficult for
attackers to break the encryption easily. This complexity helps in
safeguarding sensitive data.
The DES was adopted by the National Institute of The initial permutation function takes 64 bits of plaintext,
Standards and Technology in 1977, but it is now processes it, and outputs another 64 bits before proceeding to
considered outdated due to security multiple rounds of encryption. This function is crucial for the
vulnerabilities. AES replaced DES in 2001. encryption process.
AES, or Advanced Encryption Standard, is now The importance of the Feistel structure is highlighted, as it
widely used due to its robust security features organizes the rounds of encryption and ensures that the data
and efficiency. It has become the standard for is systematically transformed. This structure is foundational for
modern encryption practices. maintaining security throughout the process.
The DES encryption algorithm processes 64-bit After 16 rounds of processing, the final output consists of 64
plaintext into 64-bit ciphertext while utilizing a 56- bits that undergo a 32-bit swap function, rearranging the data
bit key and generating 48-bit round keys for its for further transformation. This swap ensures that the
16 rounds of operation. encryption remains secure.
The main key provided to the DES algorithm is The process involves an initial permutation function that
64 bits, though it is effectively reduced to a 56-bit prepares the data for encryption. This function is crucial for the
key before encryption begins. security of the algorithm.
For the encryption process, 16 round keys of 48 Each of the 16 rounds utilizes a distinct round key derived
bits each are generated from the 56-bit key, from the original key. This method enhances the complexity
essential for the algorithm's multiple rounds. and security of the encryption.
The input and output sizes of the DES algorithm
are both 64 bits, demonstrating its function as a The key length used in the DES algorithm is 56 bits, despite
block cipher for data encryption. starting with a 64-bit key. This reduction is significant for
generating round keys effectively.
Initial Permutation IP
first step of the data computation
IP reorders the input data bits
even bits to LH half, odd bits to RH half
quite regular in structure (easy in h/w)
no cryptographic value
example:
IP(675a6967 5e5a6b5a) = (ffb2194d 004df6fb)
Feistel Cipher Round
DES Round Structure
uses two 32-bit L & R halves
as for any Feistel cipher can describe as:
Li = Ri–1
Ri = Li–1 ⊕ F(Ri–1, Ki)
F takes 32-bit R half and 48-bit subkey:
● expands R to 48-bits using perm E
● adds to subkey using XOR
● passes through 8 S-boxes to get 32-bit result
● finally permutes using 32-bit perm P
The video explains the single round of the
DES algorithm, focusing on the processes
including initial and inverse permutations.
Understanding these functions is crucial
for grasping how DES encryption works.
DES Round Structure
The initial permutation alters the positions
of the bits in a 64-bit plaintext, preparing it
for the round function. This foundational
step is essential for subsequent
encryption.
DES Key Schedule the round). After shifting, a Permuted Choice 2 (PC-2)
operation is applied to produce the 48-bit round keys
(K1 to K16).
forms subkeys used in each round these keys is reversed, using K16 for the first round,
K15 for the second, and so on, effectively reversing the
encryption process.
3. **The Use of the 56-bit Key in DES and Brute-Force Attack on DES**
DES uses a **56-bit key**, which means there are **2 possible keys
(around 7.2 × 10¹ keys)**. In a brute-force attack, an attacker attempts
every possible key until the correct one is found. While this was
computationally expensive in the past, advancements in computing
power have made brute-force attacks feasible. DES was cracked in
**less than three days** using a specialized hardware-based DES
cracker that cost under **$250,000**. As a result, DES is considered
**insecure** for modern applications.
Strength of DES – Key Size
Refer word docx
56-bit keys have 256 = 7.2 x 1016 values
brute force search looks hard
recent advances have shown is possible
● in 1997 on Internet in a few months
● in 1998 on dedicated h/w (EFF) in a few days
● in 1999 above combined in 22hrs!
still must be able to recognize plaintext
must now consider alternatives to DES
Strength of DES – Analytic
Attacks
now have several analytic attacks on DES
these utilise some deep structure of the cipher
● by gathering information about encryptions
● can eventually recover some/all of the sub-key bits
● if necessary then exhaustively search for the rest
generally these are statistical attacks
● differential cryptanalysis
● linear cryptanalysis
● related key attacks
The Use of the 56-bit Key in DES and
Brute-Force Attack on DES
Strength of DES – Timing DES uses a 56-bit key, which means there are
2 possible keys (around 7.2 × 10¹ keys). In a
brute-force attack, an attacker attempts every
possible key until the correct one is found.
XOR that
for modern
Final
S-box
cracked in less
andcracker withcost
substitution,
than three
round
under
applications.
Permutation
keys)
brute-force attacks
days usingpermutation,
a specialized
$250,000. As a result, DES is
(Inverse IP)