例题一
N : 4606578138842896098963720565855441724853181170262462638997443292374927018206272195560077882005901191
3617389598900138215153600685382332638289236314360431451868638878600298924880081486124859507532627709
9645338694977097459168530898776007293695728101976069423971696524237755227187061418202849911479124793
990722597
e : 3546111024413075720565721818279258991983453502287537309310893932754639165444566268942454150961078344
6577840953237318712531855461472259930179152891621283936812106603554100880826153450058602365276771227
1625785204280964688004680328300124849680477105302519377370092578107827116821391826210972320377614967
547827619
enc : 38230991316229399651823567590692301060044620412191737764632384680546256228451518238842965221394711
84833783245944384444688946836215418821484073674465788585894381017767587199111146665315825719113960
56999163473082949956645302808168504827405306022545591237591211063383592202426377759190269335633260
69449424391192
题目已经给出了n,e,但是e特别大,这种情况下可以使用wiener attack 的方法进行破解,RsaCtfTool集成了这种方法,安装教程在上一篇blog中
使用RsaCtfTool工具
python RsaCtfTool.py --createpub -n 460657813884289609896372056585544172485318117026246263899744329237492701820627219556007788200590119136173895989001382151536006853823326382892363143604314518686388786002989248800814861248595075326277099645338694977097459168530898776007293695728101976069423971696524237755227187061418202849911479124793990722597 -e 354611102441307572056572181827925899198345350228753730931089393275463916544456626894245415096107834465778409532373187125318554614722599301791528916212839368121066035541008808261534500586023652767712271625785204280964688004680328300124849680477105302519377370092578107827116821391826210972320377614967547827619 > test.pem
python RsaCtfTool.py --publickey test.pem --private > test.key
python RsaCtfTool.py --key test.key --dumpkey
这时可以看到pq的值,而我们解码要用的就是pq
编写脚本
#!/usr/bin/python
# -*- coding:utf8 -
from libnum import n2s,s2n
def gcd(a, b): #求最大公约数
if a < b:
a, b = b, a
while b != 0:
temp = a % b
a = b
b = temp
return a
def egcd(a,b): #扩展欧几里得算法
if a==0:
return (b,0,1)
else:
g,y,x=egcd(b%a,a)
return (g,x-(b//a)*y,y)
def modinv(a,m):
g,x,y=egcd(a,m)
if g!=1:
raise Exception('modular inverse does not exist')
else:
return x%m
if __name__ == '__main__':
p =15991846970993213322072626901560749932686325766403404864023341810735319249066370916090640926219079368845510444031400322229147771682961132420481897362843199
q =28805791771260259486856902729020438686670354441296247148207862836064657849735343618207098163901787287368569768472521344635567334299356760080507454640207003
e = 354611102441307572056572181827925899198345350228753730931089393275463916544456626894245415096107834465778409532373187125318554614722599301791528916212839368121066035541008808261534500586023652767712271625785204280964688004680328300124849680477105302519377370092578107827116821391826210972320377614967547827619
d =modinv(e,(p-1)*(q-1))
c =38230991316229399651823567590692301060044620412191737764632384680546256228451518238842965221394711848337832459443844446889468362154188214840736744657885858943810177675871991111466653158257191139605699916347308294995664530280816850482740530602254559123759121106338359220242637775919026933563326069449424391192
n =p*q
m = pow(c,d,n)
print n2s(m)
得到flag