TY B.Tech Trimester-VIII (AY 2019-2020) Computer Science and Engineering
TY B.Tech Trimester-VIII (AY 2019-2020) Computer Science and Engineering
TY B.Tech Trimester-VIII (AY 2019-2020) Computer Science and Engineering
Disclaimer:
a. Information included in these slides came from multiple sources. We have tried our
best to cite the sources. Please refer to the references to learn about the sources,
when applicable.
b. The slides should be used only for preparing notes, academic purposes (e.g. in teaching
a class), and should not be used for commercial purposes.
Unit II: Mathematical Foundations and Public
Key Cryptography
1 To program asymmetric key cryptography such as RSA cryptography using JAVA API, Python or C++
API.
2 To program basic cryptography hash algorithm SHA1 or MD5 Use Java or Python or C++ API.
Additionally demonstrate client server authentication using socket programming.
3 Write program for demonstration of digital signature and its verification using Java or Python or C++.
Prime Numbers
Relative Prime Numbers
• Two numbers are called relatively prime if the greatest common divisor (GCD) of those
numbers is 1.
• 8 and 15 are relatively prime number.
• Examples of relatively prime numbers are: (10, 21), (14, 15), (45, 91), ....
• m mod n
• The mod with respect to n is (0, 1, 2, ... n - 1).
• Suppose m = 23 and n = 9, then
• 23 mod 9 = 5
• For any value of m, the value of m mod 9 is from (0, 1, 2, ... 8).
e.g. p = 11, q = 15
[(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
12/3/2019 Information Security: Unit - II 7
Example 1: Find the value of 7^7 mod 9.
Suppose a positive integer be p and two integers x and y are congruent mod p.
Mathematically, x ≡ y mod p if p | (x-y)
For example:
i) 5 ≡ 2 mod 3
ii) 23 ≡ -1 mod 12
ø (n) = how many numbers there are between 1 and n - 1 that are relatively prime to n.
ø (4) = 2 (1, 3 are relatively prime to 4)
ø (5) = 4 (1, 2, 3, 4 are relatively prime to 5)
ø (6) = 2 (1, 5 are relatively prime to 6)
ø (7) = 6 (1, 2, 3, 4, 5, 6 are relatively prime to 7)
This theorem generalizes Fermat’s theorem and is an important key to the RSA algorithm.
In other words, If a and p are relatively prime, with a being the smaller integer, then when we
multiply a with itself (p) times and divide the result by p, the remainder will be 1.
• GCD (p, q) is the largest number that divides evenly both p and q.
• Euclidean algorithm is used to compute the greatest common divisor (GCD) of two integer
numbers.
Example:
1. Compute GCD (997, 366) using Euclid's algorithm
2. Compute GCD (2222, 1234) using Euclid's algorithm.
• Suppose p and q are two integer numbers. There exist two integers x and y such that
xp + yq = GCD(p, q).
Extended Euclidean algorithm is used to find the value of x and y.
Write the two linear combinations vertically as shown below and apply Euclid's algorithm to
get g = GCD(p, q) and the values of x and the y to satisfy the equation
xp + yq = g.
x = 1.x + 0.y
y = 0.x+1.y
r = 1.x + (-z) .y
• 3 = 15 - 6(2)
• 3 = 15 - [36 - 15(2)](2)
• 3 = 15(5) - 36(2)
• 3 = [51 - 36(1)](5) - 36(2)
• 3 = 51(5) - 36(5) - 36(2)
• 3 = 51(5) - 36(7)
• 3 = 51(5) + 36(-7)
• Therefore, the values of p = 5 and q = -7 and GCD = 3.
Ans: 89469
My name is
Encrypt G%er@17*
Umesh
Algorithm K1
My name is
G%er@17* Decrypt
Umesh
Algorithm K2
Key details A B
should know should know
A’s private key Yes No
A’s public key Yes Yes
B’s private key No Yes
B’s public key Yes Yes
Size of resulting encrypted text usually same or Size of resulting encrypted text more than
less than original original
Problem of Key Exchange No Problem of Key Exchange
Easier to implement Practically more difficult
Exemple: DES, 3DES, AES, and RC4 Exemple: Diffie-Hellman, RSA.
3. Select the public key (i.e. the encryption key) E such that it is not a factor of (P – 1) and (Q – 1)
5. For encryption, calculate the cipher text CT from the plain text PT : CT = PTE mod N
7. For decryption, calculate the plain text PT from the cipher text CT as follows:
PT = CTD mod N
12/3/2019 Information Security: Unit - II 27
B’s public key as 5 (known to A and B) and B’s private key as 77 (known only to B)
P = 7 and Q = 17
A F F 6 4177 F
41 B
65
Result modulo 119 Result modulo 119
= 41 6 F
12/3/2019 Information Security: Unit - II 28
RSA En/decryption
each user generates a public/private key pair by: selecting two large primes at random:
p, q
computing their system modulus n = (p * q)
Compute: ø(n) = (p -1)(q -1)
selecting at random the encryption key (public) e, where 1< e < ø(n), gcd(e,ø(n)) = 1
solve following equation to find decryption key d
d * e = 1 mod ø(n) and 0 ≤ d ≤ n
publish their public encryption key: PU = {e, n}
keep secret private decryption key: PR = {d, n}
12/3/2019 Information Security: Unit - II 30
to encrypt a message M the sender:
• obtains public key of recipient PU = {e, n}
• computes Ciphertext : C = Me mod n, where 0 ≤ M < n
to decrypt the ciphertext C the owner:
• uses their private key PR = {d, n}
• computes: M = Cd mod n
note that the message M must be smaller than the modulus n (block if needed)
Disadvantages of RSA
If any one value of p, q, Φ(n) and e is known then the other values can be calculated.
To protect the encryption, the minimum number of bits in n should be of 2048 bits.
Example 2: Using RSA algorithm to encrypt the message m = “6” use parameters p = 3,
The total length of this should be 64 bits less than a multiple of 512
For example, it can be 448 bits (448 = 512 – 64) or 960 bits
(960 = [2 x 512] – 64) or 1472 (1472 = [3 x 512] – 64), etc.
12/3/2019 Information Security: Unit - II 40
Step 2: Append length
Add a 64-bit binary-string which is the representation of the message’s length
If the original length is greater than 264, then only the low-order 64 bits of the length are used.
Thus, field contains the length of the original message, modulo 264.
64 bits
Data to be hashed (digested)
The length of the original message (excluding the padding) is calculated, and is appended to
the end of the message block + padding. This length is expressed in 64 bits. If the length of
the message exceeds 64 bits (i.e. it is greater than 264, then only the last 64 bits of the length
are used, i.e. a modulus 64 of the length is taken. After the 64-bit length of the message is
appended, this becomes the final message (i.e. the message to be hashed).
12/3/2019 The length of the message is nowInformation
a multiple Security:
of 512 bits.
Unit - II 41
Step 3: Divide the input into 512-bit blocks
Preimage: An attacker has an output and finds an input that hashes to that output
2nd Preimage: An attacker has an output and an input x and finds a 2nd input that produces
the same output as x
Collision: An attacker finds two inputs that hash to the same output
Length Extension: An attacker, knowing the length of message M and a digest of M signed
by a sender can extend M with an additional message N and can compute the digest of M || N
even without the key used to sign the digest of M
Attack to try and find two Requires 264 operations to break in Requires 280 operations to
messages producing the same break in
message digest
Successful attacks so far There have been reported attempts to No such claims so far
some extent
Speed Faster (64 iterations, and 128-bit Slower (80 iterations, and 160-
buffer) bit buffer)
Software implementation Simple, does not need any large Simple, does not need any large
programs or complex tables programs or complex tables
12/3/2019 Information Security: Unit - II 50
Symmetric and Asymmetric Key Cryptography Together
We construct 6 points