当前位置:网站首页>BUUCTF-RSA4
BUUCTF-RSA4
2022-07-27 21:07:00 【[email protected]】
1.题目代码:
# N = 331310324212000030020214312244232222400142410423413104441140203003243002104333214202031202212403400220031202142322434104143104244241214204444443323000244130122022422310201104411044030113302323014101331214303223312402430402404413033243132101010422240133122211400434023222214231402403403200012221023341333340042343122302113410210110221233241303024431330001303404020104442443120130000334110042432010203401440404010003442001223042211442001413004
# c = 310020004234033304244200421414413320341301002123030311202340222410301423440312412440240244110200112141140201224032402232131204213012303204422003300004011434102141321223311243242010014140422411342304322201241112402132203101131221223004022003120002110230023341143201404311340311134230140231412201333333142402423134333211302102413111111424430032440123340034044314223400401224111323000242234420441240411021023100222003123214343030122032301042243
#
# N = 302240000040421410144422133334143140011011044322223144412002220243001141141114123223331331304421113021231204322233120121444434210041232214144413244434424302311222143224402302432102242132244032010020113224011121043232143221203424243134044314022212024343100042342002432331144300214212414033414120004344211330224020301223033334324244031204240122301242232011303211220044222411134403012132420311110302442344021122101224411230002203344140143044114
# c = 112200203404013430330214124004404423210041321043000303233141423344144222343401042200334033203124030011440014210112103234440312134032123400444344144233020130110134042102220302002413321102022414130443041144240310121020100310104334204234412411424420321211112232031121330310333414423433343322024400121200333330432223421433344122023012440013041401423202210124024431040013414313121123433424113113414422043330422002314144111134142044333404112240344
#
# N = 332200324410041111434222123043121331442103233332422341041340412034230003314420311333101344231212130200312041044324431141033004333110021013020140020011222012300020041342040004002220210223122111314112124333211132230332124022423141214031303144444134403024420111423244424030030003340213032121303213343020401304243330001314023030121034113334404440421242240113103203013341231330004332040302440011324004130324034323430143102401440130242321424020323
# c = 10013444120141130322433204124002242224332334011124210012440241402342100410331131441303242011002101323040403311120421304422222200324402244243322422444414043342130111111330022213203030324422101133032212042042243101434342203204121042113212104212423330331134311311114143200011240002111312122234340003403312040401043021433112031334324322123304112340014030132021432101130211241134422413442312013042141212003102211300321404043012124332013240431242
2.复现
中国剩余定理:

N1,N2,N3两两互质
c1=m^e mod n1
c2=m^e mod n2
c3=m^e mod n3
当m^e<n1,n2,n3时,所以当m和e足够小时才可以用这个方法
m^e=c1 mod n1
m^e=c2 mod n2
m^e=c3 mod n3
N=n1*n2*n3
N1=N/N1,N2=N/N2,N3=N/N3
根据中国剩余定理:
m^e=c1*N1*invert(N1,n1)+c2*N2*invert(N2,n2)+c3*N3*invert(N3,n3) mod N
invert(N2,n2)是N2对n2的逆元。
对m^e开e次根就可以求出m。
本题的c和n给的是5进制的数,不仔细看还看不出来。
import gmpy2
import libnum
N1 = int('331310324212000030020214312244232222400142410423413104441140203003243002104333214202031202212403400220031202142322434104143104244241214204444443323000244130122022422310201104411044030113302323014101331214303223312402430402404413033243132101010422240133122211400434023222214231402403403200012221023341333340042343122302113410210110221233241303024431330001303404020104442443120130000334110042432010203401440404010003442001223042211442001413004',5)
c1 = int('310020004234033304244200421414413320341301002123030311202340222410301423440312412440240244110200112141140201224032402232131204213012303204422003300004011434102141321223311243242010014140422411342304322201241112402132203101131221223004022003120002110230023341143201404311340311134230140231412201333333142402423134333211302102413111111424430032440123340034044314223400401224111323000242234420441240411021023100222003123214343030122032301042243',5)
N2 = int('302240000040421410144422133334143140011011044322223144412002220243001141141114123223331331304421113021231204322233120121444434210041232214144413244434424302311222143224402302432102242132244032010020113224011121043232143221203424243134044314022212024343100042342002432331144300214212414033414120004344211330224020301223033334324244031204240122301242232011303211220044222411134403012132420311110302442344021122101224411230002203344140143044114',5)
c2 = int('112200203404013430330214124004404423210041321043000303233141423344144222343401042200334033203124030011440014210112103234440312134032123400444344144233020130110134042102220302002413321102022414130443041144240310121020100310104334204234412411424420321211112232031121330310333414423433343322024400121200333330432223421433344122023012440013041401423202210124024431040013414313121123433424113113414422043330422002314144111134142044333404112240344',5)
N3 = int('332200324410041111434222123043121331442103233332422341041340412034230003314420311333101344231212130200312041044324431141033004333110021013020140020011222012300020041342040004002220210223122111314112124333211132230332124022423141214031303144444134403024420111423244424030030003340213032121303213343020401304243330001314023030121034113334404440421242240113103203013341231330004332040302440011324004130324034323430143102401440130242321424020323',5)
c3 = int('10013444120141130322433204124002242224332334011124210012440241402342100410331131441303242011002101323040403311120421304422222200324402244243322422444414043342130111111330022213203030324422101133032212042042243101434342203204121042113212104212423330331134311311114143200011240002111312122234340003403312040401043021433112031334324322123304112340014030132021432101130211241134422413442312013042141212003102211300321404043012124332013240431242',5)
e=3
N=N1*N2*N3
# c1=m^e mod N1
# c2=m^e mod N2
# c3=m^e mod N3
m=(c1*N//N1*gmpy2.invert(N//N1,N1)+c2*N//N2*gmpy2.invert(N//N2,N2)+c3*N//N3*gmpy2.invert(N//N3,N3))%N
m,f=gmpy2.iroot(m,3)
# print(m)259362307225540148883586283191025214233097658309244310540770399135748418469298031742173624766441014006294782333
print(libnum.n2s(int(m)))
# b'noxCTF{D4mn_y0u_h4s74d_wh47_4_b100dy_b4s74rd!}'这里只有3组c,n,但是组数多的话就不好一个一个的算了,所以写一个通用的脚本。
import gmpy2
import libnum
# n1,n2,n3......两两互质
n1 = int('331310324212000030020214312244232222400142410423413104441140203003243002104333214202031202212403400220031202142322434104143104244241214204444443323000244130122022422310201104411044030113302323014101331214303223312402430402404413033243132101010422240133122211400434023222214231402403403200012221023341333340042343122302113410210110221233241303024431330001303404020104442443120130000334110042432010203401440404010003442001223042211442001413004',5)
c1 = int('310020004234033304244200421414413320341301002123030311202340222410301423440312412440240244110200112141140201224032402232131204213012303204422003300004011434102141321223311243242010014140422411342304322201241112402132203101131221223004022003120002110230023341143201404311340311134230140231412201333333142402423134333211302102413111111424430032440123340034044314223400401224111323000242234420441240411021023100222003123214343030122032301042243',5)
n2 = int('302240000040421410144422133334143140011011044322223144412002220243001141141114123223331331304421113021231204322233120121444434210041232214144413244434424302311222143224402302432102242132244032010020113224011121043232143221203424243134044314022212024343100042342002432331144300214212414033414120004344211330224020301223033334324244031204240122301242232011303211220044222411134403012132420311110302442344021122101224411230002203344140143044114',5)
c2 = int('112200203404013430330214124004404423210041321043000303233141423344144222343401042200334033203124030011440014210112103234440312134032123400444344144233020130110134042102220302002413321102022414130443041144240310121020100310104334204234412411424420321211112232031121330310333414423433343322024400121200333330432223421433344122023012440013041401423202210124024431040013414313121123433424113113414422043330422002314144111134142044333404112240344',5)
n3 = int('332200324410041111434222123043121331442103233332422341041340412034230003314420311333101344231212130200312041044324431141033004333110021013020140020011222012300020041342040004002220210223122111314112124333211132230332124022423141214031303144444134403024420111423244424030030003340213032121303213343020401304243330001314023030121034113334404440421242240113103203013341231330004332040302440011324004130324034323430143102401440130242321424020323',5)
c3 = int('10013444120141130322433204124002242224332334011124210012440241402342100410331131441303242011002101323040403311120421304422222200324402244243322422444414043342130111111330022213203030324422101133032212042042243101434342203204121042113212104212423330331134311311114143200011240002111312122234340003403312040401043021433112031334324322123304112340014030132021432101130211241134422413442312013042141212003102211300321404043012124332013240431242',5)
e=3
n=[n1,n2,n3]
c=[c1,c2,c3]
N=1
for i in n:
N=N*i
m_e=0#m的e次方
for i in range(len(n)):
m_e=m_e+c[i]*N//n[i]*gmpy2.invert(N//n[i],n[i])
m_e=m_e%N
m,f=gmpy2.iroot(m_e,e)
flag=libnum.n2s(int(m))
print(flag)
# b'noxCTF{D4mn_y0u_h4s74d_wh47_4_b100dy_b4s74rd!}'总结:当题目给出多组n,c,而且多组n两两互质,m^e<每一个n时,就可以用这个方法。
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_61774705/article/details/124696493
边栏推荐
- TFRecord的Shuffle、划分和读取
- Remotely debug idea, configure remote debug, and add JVM startup parameter -xdebug in the program of remote server
- [signal denoising] signal denoising based on Kalman filter with matlab code
- 29. Learn the stacked column chart of highcharts using percentage
- 台积电3nm细节曝光:晶体管密度高达2.5亿个/mm²,性能及能效大幅提升
- MySQL data query (where)
- 【C语言】通讯录(动态版本)
- The share price soared 180.46%! Shanghai silicon industry, the leader of domestic large silicon wafers, is listed: the cumulative net profit in recent four years is less than 60million
- Record the errors about formatc in R language
- Explain the idempotence of distributed system in detail
猜你喜欢

2022 summer vacation daily question (5)

Application of user portrait in precise push of wechat official account of scientific journals

2022 International Conference on civil, building and Environmental Engineering (iccaee 2022)

【JS 逆向百例】某公共资源交易网,公告 URL 参数逆向分析

Is it really hard to understand? What level of cache is the recyclerview caching mechanism?

TOGAF10标准读书会首场活动圆满举办,精彩时刻回顾!

【C语言】通讯录(动态版本)
![[December Haikou] the 6th International Conference on ships, marine and Maritime Engineering in 2022 (naome 2022)](/img/a4/041268aadd5d8ff493b52ead9c5e79.png)
[December Haikou] the 6th International Conference on ships, marine and Maritime Engineering in 2022 (naome 2022)

Spark 离线开发框架设计与实现

JUC工具包学习
随机推荐
用3dmax做折扇的思路方法与步骤
Why do I need to wait for 2msl?
Error:svn: E155010: ‘/Users/.../Desktop/wrokspace/xxx‘ is scheduled for addition, but is missing
Is it really hard to understand? What level of cache is the recyclerview caching mechanism?
给网站套上Cloudflare(以腾讯云为例)
一位软件投资者的独白:我为什么不追逐快速增长的公司
The total investment is 60billion! Foxconn semiconductor high-end package test project officially settled in Qingdao
The share price soared 180.46%! Shanghai silicon industry, the leader of domestic large silicon wafers, is listed: the cumulative net profit in recent four years is less than 60million
Your list is too laggy? These four optimizations can make your list silky smooth
org.junit.runners.model.InvalidTestClassError: Invalid test class ‘com.zhj.esdemo.MysqlTests‘: 1.
2022年土木,建筑与环境工程国际会议(ICCAEE 2022)
NB-IoT产业的现状与未来:跨过1亿出货门槛,奔向5G大连接!
File&递归14.1
疫情之下,台积电一季度增长超预期,7nm占比35%!二季度或创新高
2022 summer vacation daily question (5)
一加将在2020年释放ODM订单,发力中低端市场
Normality of confidence interval
Common Taylor expansion
The technology of applet container is very promising, which can greatly improve the efficiency of mobile R & D
Nail alarm tool