Assignment 1
Assignment 1
Algorithm:
1. Select two large prime no's “p” and “q”.
2. Calculate n = p*q
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
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