jukaukor

Factoring_PollardRho_int.py

Aug 19th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. # RSA-avaimen murtaminen: tulontekijöiden p ja q löytäminen Pythonilla
  2. # Pollard Pho-menetelmällä
  3. # Sopii suurillekin (yli 100 bit avaimille)
  4. # Pääosa source: Pollard Rho algorithm - Wikipedia
  5. # Factoring_PollardRho_int.py
  6. # Juhani Kaukoranta, versio 20.8.2019
  7.  
  8. from math import gcd
  9. import time
  10.  
  11. def PollardRho(n):
  12. x, y, p = 2, 2, 1
  13. f=lambda x: (x**2+1) % n
  14. while p == 1:
  15. x = f(x)
  16. y = f(f(y))
  17. p = gcd(abs(x-y),n)
  18. if p == n:
  19. return "Ei tekijöitä, avain alkuluku tms"
  20. else:
  21. q = n // p
  22. return [p,q]
  23.  
  24. n= int(input("anna RSA-avain "))
  25. number = n
  26. time0 = time.perf_counter() # timer alku
  27. print("Alkulukutekijät [p,q] = ",PollardRho(n))
  28. time1 = time.perf_counter()
  29. print("Aikaa kului ",time1-time0," sekuntia")
Advertisement
Add Comment
Please, Sign In to add comment