Skip to content

Commit 4ce8ed9

Browse files
Algorithm for RSA
RSA algorithm is 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 Private key is kept private.
1 parent 220f043 commit 4ce8ed9

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

RSA_algorithm.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from decimal import Decimal
2+
3+
def gcd(a,b):
4+
if b==0:
5+
return a
6+
else:
7+
return gcd(b,a%b)
8+
p = int(input('Enter the value of p = '))
9+
q = int(input('Enter the value of q = '))
10+
no = int(input('Enter the value of text = '))
11+
n = p*q
12+
t = (p-1)*(q-1)
13+
14+
for e in range(2,t):
15+
if gcd(e,t)== 1:
16+
break
17+
18+
19+
for i in range(1,10):
20+
x = 1 + i*t
21+
if x % e == 0:
22+
d = int(x/e)
23+
break
24+
ctt = Decimal(0)
25+
ctt =pow(no,e)
26+
ct = ctt % n
27+
28+
dtt = Decimal(0)
29+
dtt = pow(ct,d)
30+
dt = dtt % n
31+
32+
print('n = '+str(n)+' e = '+str(e)+' t = '+str(t)+' d = '+str(d)+' cipher text = '+str(ct)+' decrypted text = '+str(dt))

0 commit comments

Comments
 (0)