二分搜索爆破rsa的p或q
[BJDCTF 2nd]rsa1
#coding:utf-8 from libnum import * from gmpy2 import * import math e=12990949 p_2_q_2=183782731007174022947897678873654342408787163368897466509212057170406620184774600954331502908738808990728948715434562369036827239969020416321160032788058626544559653093499687137741603040727426232970318760111847913623422508141175128591799138075029801779143469341858715175680005943297247688087384253865281853050 p_q=3420996695751940271038343942117267156606574468394879530169427300611581223752387528607212545036324070243053245775761931418594947344069069518548266438742826 c=77753506402159624304511993967611288830630810624185076810348915806660406747063755097830538484527135284551616435501620038150981343500921975145508256290568938137631482115138263326426719577498702230890028813607371846008623201697365600671694748995508679434186406300609163911109861417963646898654602161609938964074 n = (p_2_q_2-(p_q)*(p_q))/2 #p*q left = 1 right = n q = left + (right - left)/2 while 1: k = q*q+p_q*q if k == n: print q break elif k < n: left = q + 1 elif k > n: right = q - 1 q = left + (right - left)/2 p = n/q phi = (p-1)*(q-1) d = invert(e,phi) print n2s(pow(c,d,n))