def __init__(self, n, e):
self.d = None
self.p = None
self.q = None
sys.setrecursionlimit(100000)
frac = self.rational_to_contfrac(e, n)
convergents = self.convergents_from_contfrac(frac)
for (k,d) in convergents:
if k!=0 and (e*d-1)%k == 0:
phi = (e*d-1)//k
s = n - phi + 1
discr = s*s - 4*n
if(discr>=0):
t = self.is_perfect_square(discr)
if t!=-1 and (s+t)%2==0:
self.d = d
x = Symbol('x')
roots = solve(x**2 - s*x + n, x)
if len(roots) == 2:
self.p = roots[0]
self.q = roots[1]
break
评论列表
文章目录