Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #python2 -m primefac -m=p+1 13600689950702678449784835151815974930081348852322430023033556990750407302536196017142902387097892642345597564002803049369859021622154057824025261445149722108978168478137715149349659619454621524807710623319033897949123127670966633488318687764955391182209483781455502811562493433978547603095334295954771596786145240556520883744576353821136738684148011064935790222495233081914179923414412186454172809843508100994530119340028548341289369372240024738698118638987563907
  2.  
  3. #p = 26095988705098082141146804081349098362896803568710141131962347542899307107886799504316790900281317552305916634959743976639058747315050655853768513454406251
  4.  
  5. #q= n/p = 521179331597643717826719455288904380283486818776725416395655915960819344127365068024226118263530149099094250120477785823751838585076764808018002955416767480620795032894457484184359000800607418687273707348464760198903221109476238119882003449193031638494925360314500101182222492365386087041855756138309223907657
  6.  
  7.  
  8. import gmpy2
  9.  
  10. N = 521179331597643717826719455288904380283486818776725416395655915960819344127365068024226118263530149099094250120477785823751838585076764808018002955416767480620795032894457484184359000800607418687273707348464760198903221109476238119882003449193031638494925360314500101182222492365386087041855756138309223907657
  11.  
  12. def fermat_factor(n):
  13. assert n % 2 != 0
  14.  
  15. a = gmpy2.isqrt(n)
  16. b2 = gmpy2.square(a) - n
  17.  
  18. while not gmpy2.is_square(b2):
  19. a += 1
  20. b2 = gmpy2.square(a) - n
  21.  
  22. p = a + gmpy2.isqrt(b2)
  23. q = a - gmpy2.isqrt(b2)
  24.  
  25. return int(p), int(q)
  26.  
  27. if __name__ == "__main__":
  28. (p, q) = fermat_factor(N)
  29.  
  30. print("p = {}".format(p))
  31. print("q = {}".format(q))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement