Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ashutosh1206
GitHub Repository: ashutosh1206/crypton
Path: blob/master/RSA-encryption/Attack-Wiener/exploit.py
1402 views
1
from sage.all import *
2
3
def wiener(e, n):
4
m = 12345
5
c = pow(m, e, n)
6
lst = continued_fraction(Integer(e)/Integer(n))
7
conv = lst.convergents()
8
for i in conv:
9
k = i.numerator()
10
d = int(i.denominator())
11
try:
12
m1 = pow(c, d, n)
13
if m1 == m:
14
print "[*] Found d: ", d
15
return d
16
except:
17
continue
18
return -1
19
20