Skip to content

Commit

Permalink
Now finds p and q roots
Browse files Browse the repository at this point in the history
  • Loading branch information
staslyakhov committed Oct 23, 2017
1 parent 0426cca commit 4dbd02d
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def continued_fraction(self):
num = den
den = remainder

def convergent_expansion(self):
def convergents(self):
k = [1, 0]
h = [0, 1]
for i, expansion in enumerate(self.expansions):
Expand All @@ -32,11 +32,10 @@ def convergent_expansion(self):
yield k_new, h_new

def phi(self):
c = self.convergent_expansion()
c = self.convergents()
next(c)
for k, h in c:
yield self.e * k - 1 // h

yield (self.e * k - 1) // h

def solve_poly(self):
x = Symbol('x')
Expand All @@ -45,19 +44,18 @@ def solve_poly(self):
roots = solve(p[0]*x**2 - p[1]*x + p[2], x)

if roots[0] * roots[1] == self.N:
print(roots)


return roots
return False

def main():
e = 165528674684553774754161107952508373110624366523537426971950721796143115780129435315899759675151336726943047090419484833345443949104434072639959175019000332954933802344468968633829926100061874628202284567388558408274913523076548466524630414081156553457145524778651651092522168245814433643807177041677885126141
n = 380654536359671023755976891498668045392440824270475526144618987828344270045182740160077144588766610702530210398859909208327353118643014342338185873507801667054475298636689473117890228196755174002229463306397132008619636921625801645435089242900101841738546712222819150058222758938346094596787521134065656721069
e = 0x0285f8d4fe29ce11605edf221868937c1b70ae376e34d67f9bb78c29a2d79ca46a60ea02a70fdb40e805b5d854255968b2b1f043963dcd61714ce4fc5c70ecc4d756ad1685d661db39d15a801d1c382ed97a048f0f85d909c811691d3ffe262eb70ccd1fa7dba1aa79139f21c14b3dfe95340491cff3a5a6ae9604329578db9f5bcc192e16aa62f687a8038e60c01518f8ccaa0befe569dadae8e49310a7a3c3bddcf637fc82e5340bef4105b533b6a531895650b2efa337d94c7a76447767b5129a04bcf3cd95bb60f6bfd1a12658530124ad8c6fd71652b8e0eb482fcc475043b410dfc4fe5fbc6bda08ca61244284a4ab5b311bc669df0c753526a79c1a57
n = 0x02aeb637f6152afd4fb3a2dd165aec9d5b45e70d2b82e78a353f7a1751859d196f56cb6d11700195f1069a73d9e5710950b814229ab4c5549383c2c87e0cd97f904748a1302400dc76b42591da17dabaf946aaaf1640f1327af16be45b8830603947a9c3309ca4d6cc9f1a2bcfdacf285fbc2f730e515ae1d93591ccd98f5c4674ec4a5859264700f700a4f4dcf7c3c35bbc579f6ebf80da33c6c11f68655092bbe670d5225b8e571d596fe426db59a6a05aaf77b3917448b2cfbcb3bd647b46772b13133fc68ffabcb3752372b949a3704b8596df4a44f085393ee2bf80f8f393719ed94ab348852f6a5e0c493efa32da5bf601063a033beaf73ba47d8205db
attack = WeinerAttack(e, n)
attack.continued_fraction()

attack.solve_poly()


roots = attack.solve_poly()
print('p: ', roots[0])
print('q: ', roots[1])

if __name__ == '__main__':
main()

0 comments on commit 4dbd02d

Please sign in to comment.