0% found this document useful (0 votes)
40 views

Assignment 1

The document describes the RSA algorithm for asymmetric cryptography. It explains that RSA uses a public key and private key, with the public key given to everyone and the private key kept secret. It then lists the 6 steps of the RSA algorithm: 1) select two prime numbers p and q, 2) calculate n = p*q, 3) calculate Euler's totient function f, 4) find the encryption exponent e such that gcd(e,f)=1, 5) find the decryption exponent d such that e*d mod f = 1, and 6) encrypt as C = Me mod n and decrypt as P = Cd mod n. It also includes a Python implementation of the RSA algorithm.

Uploaded by

R Alchemist
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Assignment 1

The document describes the RSA algorithm for asymmetric cryptography. It explains that RSA uses a public key and private key, with the public key given to everyone and the private key kept secret. It then lists the 6 steps of the RSA algorithm: 1) select two prime numbers p and q, 2) calculate n = p*q, 3) calculate Euler's totient function f, 4) find the encryption exponent e such that gcd(e,f)=1, 5) find the decryption exponent d such that e*d mod f = 1, and 6) encrypt as C = Me mod n and decrypt as P = Cd mod n. It also includes a Python implementation of the RSA algorithm.

Uploaded by

R Alchemist
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment – 1

Topic : RSA Algorithm in Cryptography

Submitted by : Aditya Ranjan (02)


Rishi Raj Chaurasia (31)
RSA algorithm is asymmetric cryptography algorithm. This
means that it works on two different keys i.e. Public
Key and Private Key. Public Key is given to everyone and
Private key is kept private.

Algorithm:
1. Select two large prime no's “p” and “q”.

2. Calculate n = p*q

3. Calculate Euler's Toitient function ( f ) = (p - 1)*(q - 1)

4. Find a small exponent say “e” such that gcd(e,f) = 1 and


1 < e < f.

5. Find “d” such that (e*d) mod( f ) = 1.

6. If value of plain text is M (should be less than n) then


For Encryption : C = Me mod n
For Decryption : P = Cd mod n
Implementation ( in Python ):
# RSA Algorithm in Cryptography

def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)

def RSA_Algorithm():
p = int(input('Enter the value of first prime no. (p) : '))
q = int(input('Enter the value of second prime no. (q) : '))
M = int(input('Enter the value of PlainText (less than '+str((p*q))+') : '
))
n = p*q
f = (p-1)*(q-1) # Euler's Toitient function

for e in range(2,f):
if gcd(e,f)== 1:
break

d = 1
while(True):
if((e*d)%f == 1):
break
else:
d += 1

Cipher =pow(M,e)%n # for Encryption


Plain = pow(Cipher,d)%n # for Decryption

print('n = '+str(n)+', e = '+str(e)+', f = '+str(f)+', d = '+str(d)+', cip


her = '+str(Cipher)+', Plain = '+str(Plain))

RSA_Algorithm()

Output:
Enter the value of first prime no. (p) : 23
Enter the value of second prime no. (q) : 89
Enter the value of PlainText (less than 2047) : 1549
n = 2047, e = 3, f = 1936, d = 1291, cipher = 1800, Plain = 1549

You might also like