We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 220f043 + 4ce8ed9 commit af332acCopy full SHA for af332ac
1 file changed
RSA_algorithm.py
@@ -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
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