Assignment of RSA Algorithm in Cryptography.
Assignment of RSA Algorithm in Cryptography.
Assignment
Department : Computer Science and Engineering.
Course Title : CSE 4103
Course No :Computer Graphics.
Assignment No : 02
Assignment Name: RSA Algorithm in Cryptography.
Submitted By Submitted To
Level: 4 Term: 1
Designation: Lecturer
Date of Experiment:
Date of submission:
Signature: …………………………………………
RSA Algorithm in Cryptography
RSA algorithm is an asymmetric cryptography algorithm. Asymmetric actually means
that it works on two different keys i.e. Public Key and Private Key. As the name
describes that the Public Key is given to everyone and the Private key is kept private.
The algorithm works as follow:
1. Select two prime numbers p and q where p≠q.
2. Calculate n=p*q
3. Calculate ⱷ(n)=(p-1)*(q-1).
4. Select such that, e is relatively prime to ⱷ(n)
i.c. (ⱷ(n),e = 1 and 1<e< ⱷ(n)
5. Calculate d= 𝑒 −1 mod ⱷ(n) or ed=1 mod ⱷ(n)
6. Public key = {e,n},private key={d,n}
7. Find out cipher text using this formula,
C=𝑃𝑒 mod n where, P< n and
C= Cipher text, P =plain text, e= Encryption key and n=block size.
8. P= 𝐶 𝑑 mode n. Plain text can be obtain using the given formula.
Where, d= decryption key.
C=𝑃𝑒 mod n where P<n where C= cipher text, P= Plain text e= Encryption key and n=
block size
Step-8: P=𝐶 𝑑 mod n Plain text P can be obtain using the given formula where d= decryption key.
temp = 0
while(1):
temp = a % h
if (temp == 0):
return h
a = h
h = temp
p=3
q=7 #here p and q is a prime number abd both are not same
print("n =", n)
break
else:
e= e+1
print("e =", e)
# d*e = 1 + k * totient
k = 2
print("d =", d)
print(f'Original message:{msg}')
# Encryption c = (msg ^ e) % n
C = pow(msg, e)
print("C =", C)
C = math.fmod(C, n)
print("C =", C)
# Decryption m = (c ^ d) % n
M = pow(C, d)
print("M =", M)
M = math.fmod(M, n)