当前位置:网站首页>[NCTF2019]babyRSA1
[NCTF2019]babyRSA1
2022-07-27 21:07:00 【[email protected]】
1.题目代码:
# from Crypto.Util.number import *
# from flag import flag
#
# def nextPrime(n):
# n += 2 if n & 1 else 1
# while not isPrime(n):
# n += 2
# return n
#
# p = getPrime(1024)
# q = nextPrime(p)
# n = p * q
# e = 0x10001
# d = inverse(e, (p-1) * (q-1))
# c = pow(bytes_to_long(flag.encode()), e, n)
#
# # d = 19275778946037899718035455438175509175723911466127462154506916564101519923603308900331427601983476886255849200332374081996442976307058597390881168155862238533018621944733299208108185814179466844504468163200369996564265921022888670062554504758512453217434777820468049494313818291727050400752551716550403647148197148884408264686846693842118387217753516963449753809860354047619256787869400297858568139700396567519469825398575103885487624463424429913017729585620877168171603444111464692841379661112075123399343270610272287865200880398193573260848268633461983435015031227070217852728240847398084414687146397303110709214913
# # c = 53827231680738281106961685582942066817579911490227778211275633014134832238745272333007211808392986170767056850411742474158261570965830550693373939878922627642112252270358807544174570567239091355252449579359069026656797771011301113927802375029286562257052624314319530035200939329243759021112800772552051182174367441120640694296786329232598986279971458038927539892556152731403000210406545059014427878106536265243057063166631693417972057529387555900565689867382278034874672741143982571879621407965511362205328096876068673856393677437055275116807199553807463776311564686898441508783814605609907556528994493400453135218042.复现
题目只给了d,c,e。所以我们要求n,我们知道e*d
1 mod (p-1)/(q-1)
所以:e*d-1=k*(p-1)(q-1)
因为p和q是1024位的二进制数,所以(p-1)*(q-1)是2048位的二进制数。
我们用print(len(bin(e*d-1)))算出e*d-1是2066位的,2066-2048=16,所以k是16位的二进制数,化为10进制就是在2^15+1-2^16-1之间,所以可以爆破k。这里直接用e*d-1%k==0爆破出的k有很多,所以我们也要同时爆破p,q。用爆破出来的k,求出(p-1)*(q-1)=e*d-1//k,然后对(p-1)*(q-1)进行开根号,很明显p,q位于(p-1)*(q-1)进行开根号的两边,而q是p的下一个素数,所以取(p-1)*(q-1)进行开根号的前一个素数和后一个素数就是p,q。
import gmpy2
import sympy
import libnum
d = 19275778946037899718035455438175509175723911466127462154506916564101519923603308900331427601983476886255849200332374081996442976307058597390881168155862238533018621944733299208108185814179466844504468163200369996564265921022888670062554504758512453217434777820468049494313818291727050400752551716550403647148197148884408264686846693842118387217753516963449753809860354047619256787869400297858568139700396567519469825398575103885487624463424429913017729585620877168171603444111464692841379661112075123399343270610272287865200880398193573260848268633461983435015031227070217852728240847398084414687146397303110709214913
c = 5382723168073828110696168558294206681757991149022777821127563301413483223874527233300721180839298617076705685041174247415826157096583055069337393987892262764211225227035880754417457056723909135525244957935906902665679777101130111392780237502928656225705262431431953003520093932924375902111280077255205118217436744112064069429678632923259898627997145803892753989255615273140300021040654505901442787810653626524305706316663169341797205752938755590056568986738227803487467274114398257187962140796551136220532809687606867385639367743705527511680719955380746377631156468689844150878381460560990755652899449340045313521804
e = int(0x10001)
# e∗d-1 = k∗ ( p − 1 ) ( q − 1 )
# print(len(bin(e*d-1)))2066-2048=16,相差16位
# 爆破k
p=0
q=0
for k in range(pow(2,15),pow(2,16)):
if (e*d-1)%k==0:
phi=(e*d-1)//k
p=sympy.prevprime(gmpy2.iroot(phi,2)[0])
q=sympy.nextprime(p)
if((p-1)*(q-1)==phi):
print(p)
print(q)
break
n=p*q
m=pow(c,d,n)
flag=libnum.n2s(int(m))
print(flag)
# 143193611591752210918770476402384783351740028841763223236102885221839966637073188462808195974548579833368313904083095786906479416347681923731100260359652426441593107755892485944809419189348311956308456459523437459969713060653432909873986596042482699670451716296743727525586437248462432327423361080811225075839
# 143193611591752210918770476402384783351740028841763223236102885221839966637073188462808195974548579833368313904083095786906479416347681923731100260359652426441593107755892485944809419189348311956308456459523437459969713060653432909873986596042482699670451716296743727525586437248462432327423361080811225076497
# b'NCTF{70u2_nn47h_14_v3ry_gOO0000000d}'总结:已知e,d,c和p,q的位数和生成方式,知道e*d-1和(p-1)*(q-1)的位数,就知道k=e*d-1//(p-1)*(q-1)的范围,爆破k,再利用p<
<q,当p,q相差不大时,可以爆破出p,q。
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_61774705/article/details/124727428
边栏推荐
- 总投资600亿!富士康半导体高端封测项目正式落户青岛
- [signal processing] weak signal detection in communication system based on the characteristics of high-order statistics with matlab code
- RPA流程自动化机器人是什么技术?如何实现办公自动化?
- 重新定义分析 - EventBridge 实时事件分析平台发布
- 真的很难理解?RecyclerView 缓存机制到底是几级缓存?
- Which one is better to request to merge -- three skills of interface request merging, and the performance directly explodes the table
- org.junit.runners.model.InvalidTestClassError: Invalid test class ‘com.zhj.esdemo.MysqlTests‘: 1.
- smartRefresh嵌套多个RecycleView滑动冲突及布局显示不全
- Binary conversion method
- Join hands with Changjiang storage, jiangbolong launches the world's smallest expansion card
猜你喜欢

org.junit.runners.model.InvalidTestClassError: Invalid test class ‘com.zhj.esdemo.MysqlTests‘: 1.
编辑复制粘贴判定问题(bug?),所见即所得显示符号问题反馈。

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

29.学习Highcharts 使用百分比的堆叠柱形图

【C语言】通讯录(动态版本)

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

The technology of applet container is very promising, which can greatly improve the efficiency of mobile R & D

基于mediapipe的姿态识别和简单行为识别

Character stream learning 14.3

Bank Marketing预测一个客户购买理财产品的成功率
随机推荐
股价暴涨180.46%!国产大硅片龙头沪硅产业上市:近4年净利累计不足6000万
台积电3nm细节曝光:晶体管密度高达2.5亿个/mm²,性能及能效大幅提升
苹果发布新款iPhone SE:搭载A13仿生处理器,售价3299元起
你的列表很卡?这4个优化能让你的列表丝般顺滑
[signal denoising] signal denoising based on Kalman filter with matlab code
Calling dht11/22 temperature and humidity sensor in Proteus simulation Arduino
用3dmax做折扇的思路方法与步骤
29. Learn the stacked column chart of highcharts using percentage
Those "experiences and traps" in the data center
如果我们是那晚负责修复 B 站崩了的开发人员
CaEGCN: Cross-Attention Fusion based Enhanced Graph Convolutional Network for Clustering 2021
ZCMU--1720: 死亡如风,我要装逼
Nature review: preferential effects in the formation of microbial communities
In 2019, the world's top ten semiconductor manufacturers: Intel returned to the first place, and apple rose sharply against the trend
新技术引领大中型企业营销新变革,用友BIP CRM重磅发布!
【12月海口】2022年第六届船舶,海洋与海事工程国际会议(NAOME 2022)
TFRecord的Shuffle、划分和读取
Your list is too laggy? These four optimizations can make your list silky smooth
JUC toolkit learning
[December Haikou] the 6th International Conference on ships, marine and Maritime Engineering in 2022 (naome 2022)
1 mod (p-1)/(q-1)
<q,当p,q相差不大时,可以爆破出p,q。