Cryptography and Network Security
Assignment 01
Name : Vikas Kushwaha
Roll No : 2021BCS0021
1. Given p = 61, q = 53, e = 17. Suppose you need to encrypt a message
represented as 65. Perform encryption and decryption using RSA algorithm.
Solution:
1. Calculate n:
n = p × q = 61 × 53 = 3233
2. Calculate φ(n):
φ(n) = (p - 1) × (q - 1) = 60 × 52 = 3120
3. Encryption:
The public key is (e, n) = (17, 3233). The message M = 65 is encrypted using the formula:
C = M^e mod n = 65^17 mod 3233
Calculating 65^17 mod 3233 gives:
C = 2790
4. Decryption:
Find the private key d, which is the modular inverse of e mod φ(n). Using the Extended
Euclidean Algorithm:
e × d ≡ 1 mod φ(n)
17 × d ≡ 1 mod 3120
We get d = 2753.
The ciphertext C = 2790 is decrypted using:
M = C^d mod n = 2790^2753 mod 3233
Calculating this gives:
M = 65
Therefore, the encrypted message is 2790, and the decrypted message is 65.
2. In RSA encryption, participant A uses two prime numbers p = 13 and q = 17.
Public key of A = 35. Find the private key.
Solution:
1. Calculate n:
n = p × q = 13 × 17 = 221
2. Calculate φ(n):
φ(n) = (p - 1) × (q - 1) = 12 × 16 = 192
3. Given Public Key e = 35, find the private key d such that:
e × d ≡ 1 mod φ(n)
35 × d ≡ 1 mod 192
Using the Extended Euclidean Algorithm, we find:
d = 11
Thus, the private key is 11.
3. Suppose two parties A & B wish to set up a common key between themselves
using Diffie-Hellman Key exchange technique. They agree on 7 as modulus and
3 as primitive root. Party A chooses 2 and B chooses 5 as their respective
private keys. Find the D-H key they exchanged.
Solution:
1. Party A's Public Key:
A = 3^2 mod 7 = 9 mod 7 = 2
2. Party B's Public Key:
B = 3^5 mod 7 = 243 mod 7 = 5
3. Shared Secret Key:
- A calculates: S_A = B^2 mod 7 = 5^2 mod 7 = 25 mod 7 = 4
- B calculates: S_B = A^5 mod 7 = 2^5 mod 7 = 32 mod 7 = 4
Thus, the shared Diffie-Hellman key is 4.
4. In a Diffie-Hellman key exchange, Alice and Bob have chosen prime value q =
17 and primitive root = 5. If Alice’s private key is 4 and Bob’s private key is 6,
what is the secret key they shared?
Solution:
1. Alice's Public Key:
A = 5^4 mod 17 = 625 mod 17 = 13
2. Bob's Public Key:
B = 5^6 mod 17 = 15625 mod 17 = 2
3. Shared Secret Key:
- Alice calculates: S_A = B^4 mod 17 = 2^4 mod 17 = 16
- Bob calculates: S_B = A^6 mod 17 = 13^6 mod 17 = 16
Thus, the shared Diffie-Hellman key is 16.
5. Consider an elliptic curve defined over a field modulo 17, given by the
equation y² = x³ + 2x + 2. If the points P = (5,1) and Q = (6,3) are on the curve,
find P + Q.
Solution:
1. Calculate Slope m:
m = (y2 - y1) / (x2 - x1) mod 17 = (3 - 1) / (6 - 5) mod 17 = 2 / 1 = 2
2. Compute x3 and y3:
x3 = (m² - x1 - x2) mod 17 = (2² - 5 - 6) mod 17 = (4 - 11) mod 17 = 10
y3 = (m(x1 - x3) - y1) mod 17 = (2(5 - 10) - 1) mod 17 = (-11) mod 17 = 6
Thus, P + Q = (10, 6).