当前位置:网站首页>[NPUCTF2020]EzRSA
[NPUCTF2020]EzRSA
2022-07-27 21:07:00 【[email protected]】
1.题目
# from gmpy2 import lcm , powmod , invert , gcd , mpz
# from Crypto.Util.number import getPrime
# from sympy import nextprime
# from random import randint
# p = getPrime(1024)
# q = getPrime(1024)
# n = p * q
# gift = lcm(p - 1 , q - 1)
# e = 54722
# flag = b'NPUCTF{******************}'
# m = int.from_bytes(flag , 'big')
# c = powmod(m , e , n)
# print('n: ' , n)
# print('gift: ' , gift)
# print('c: ' , c)
#n: 17083941230213489700426636484487738282426471494607098847295335339638177583685457921198569105417734668692072727759139358207667248703952436680183153327606147421932365889983347282046439156176685765143620637107347870401946946501620531665573668068349080410807996582297505889946205052879002028936125315312256470583622913646319779125559691270916064588684997382451412747432722966919513413709987353038375477178385125453567111965259721484997156799355617642131569095810304077131053588483057244340742751804935494087687363416921314041547093118565767609667033859583125275322077617576783247853718516166743858265291135353895239981121
#gift: 2135492653776686212553329560560967285303308936825887355911916917454772197960682240149821138177216833586509090969892419775958406087994054585022894165950768427741545736247918410255804894522085720642952579638418483800243368312702566458196708508543635051350999572787188236243275631609875253617015664414032058822919469443284453403064076232765024248435543326597418851751586308514540124571309152787559712950209357825576896132278045112177910266019741013995106579484868768251084453338417115483515132869594712162052362083414163954681306259137057581036657441897428432575924018950961141822554251369262248368899977337886190114104
#c: 3738960639194737957667684143565005503596276451617922474669745529299929395507971435311181578387223323429323286927370576955078618335757508161263585164126047545413028829873269342924092339298957635079736446851837414357757312525158356579607212496060244403765822636515347192211817658170822313646743520831977673861869637519843133863288550058359429455052676323196728280408508614527953057214779165450356577820378810467527006377296194102671360302059901897977339728292345132827184227155061326328585640019916328847372295754472832318258636054663091475801235050657401857262960415898483713074139212596685365780269667500271108538319
2.复现
直接分解n,p,q就出来了,但是发现e,和phi不互素,最大公分母是2。
所以变形一下:
c=m^e mod n
c=(m^2)^e/2 mod n
把m^2看作密文
把e//2就和phi互素了,就可以解密出m^2
然后在开根就行了。
import gmpy2
import libnum
import sympy
e = 54722
n=17083941230213489700426636484487738282426471494607098847295335339638177583685457921198569105417734668692072727759139358207667248703952436680183153327606147421932365889983347282046439156176685765143620637107347870401946946501620531665573668068349080410807996582297505889946205052879002028936125315312256470583622913646319779125559691270916064588684997382451412747432722966919513413709987353038375477178385125453567111965259721484997156799355617642131569095810304077131053588483057244340742751804935494087687363416921314041547093118565767609667033859583125275322077617576783247853718516166743858265291135353895239981121
gift=2135492653776686212553329560560967285303308936825887355911916917454772197960682240149821138177216833586509090969892419775958406087994054585022894165950768427741545736247918410255804894522085720642952579638418483800243368312702566458196708508543635051350999572787188236243275631609875253617015664414032058822919469443284453403064076232765024248435543326597418851751586308514540124571309152787559712950209357825576896132278045112177910266019741013995106579484868768251084453338417115483515132869594712162052362083414163954681306259137057581036657441897428432575924018950961141822554251369262248368899977337886190114104
c=3738960639194737957667684143565005503596276451617922474669745529299929395507971435311181578387223323429323286927370576955078618335757508161263585164126047545413028829873269342924092339298957635079736446851837414357757312525158356579607212496060244403765822636515347192211817658170822313646743520831977673861869637519843133863288550058359429455052676323196728280408508614527953057214779165450356577820378810467527006377296194102671360302059901897977339728292345132827184227155061326328585640019916328847372295754472832318258636054663091475801235050657401857262960415898483713074139212596685365780269667500271108538319
# gift = lcm(p - 1 , q - 1)最小公倍数
p=106021448991021391444550749375115277080844281746248845802565680557785009341952320484175568763707424932172033597514861602114171459176440279045761846695231788376075050452154924141266290931413542110639081792550648106240966552406813059396358355737185354885474455248579946190266152416149137616855791805617206153497
q=161136651053130509602530659420755324119806487925813087617466818245407407797561810253722204813002837916779909309520498985459703212021249251124954613236122142746302911323565396331355397916764254680629384957057354297855676493062493901977415968666512459829211010720514167083018352796496733697235524845188512914793
phi=(p-1)*(q-1)
print(gmpy2.gcd(e,phi))#2
e=e//2
d=gmpy2.invert(e,phi)
m=gmpy2.iroot(pow(c,d,n),2)[0]
flag=libnum.n2s(int(m))
print(flag)
# b'NPUCTF{[email protected]}'
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_61774705/article/details/124816077
边栏推荐
- TSMC 3nm detail exposure: transistor density as high as 250million /mm ², Greatly improved performance and energy efficiency
- 西门子PLC能否实时无线采集多处从站模拟量数据?
- Binary conversion method
- 为什么 Redis 集群要使用反向代理? 看这篇就明白了
- File & recursion 14.1
- 突发,微信重要通知
- C # delegate usage -- console project, which implements events through delegation
- Under the epidemic, TSMC's growth in the first quarter exceeded expectations, with 7Nm accounting for 35%! Second quarter or record high
- NDK series (6): let's talk about the way and time to register JNI functions
- 2022 summer vacation daily question (5)
猜你喜欢

Redefine analysis - release of eventbridge real-time event analysis platform

CaEGCN: Cross-Attention Fusion based Enhanced Graph Convolutional Network for Clustering 2021

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

数据管理的重点

Spark 离线开发框架设计与实现
![[number recognition] handwritten number recognition based on knowledge base with matlab code](/img/06/6adab955a339f453249543baab1dc6.png)
[number recognition] handwritten number recognition based on knowledge base with matlab code

详解分布式系统的幂等

如果我们是那晚负责修复 B 站崩了的开发人员

C#委托用法--控制台项目,通过委托实现事件

字符流学习14.3
随机推荐
proteus仿真arduino中调用DHT11/22温湿度传感器
Solve 5g pain points, Meizu 17 smart 5g fast and stable technology release
Those "experiences and traps" in the data center
Huawei Hongmeng 3 was officially released, and this security feature has solved a major pain point
Smartrefresh nested multiple recycleview sliding conflicts and incomplete layout display
携手长江存储,江波龙推出全球最小扩展卡
Socket interaction process of four waves
Common Taylor expansion
Figure basic knowledge code
urllib.error. URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: un
Design and implementation of spark offline development framework
Current situation and future of Nb IOT industry: cross the threshold of 100million shipments and rush to 5g connection!
请求合并哪家强——接口请求合并的3种技巧,性能直接爆表
TOGAF10标准读书会首场活动圆满举办,精彩时刻回顾!
QT with OpenGL(Shadow Mapping)(平行光篇)
Record the errors about formatc in R language
Lua基础语法学习
Introduction to several common usage scenarios of message queue
数据管理的重点
JS提升:JS中的数组扁平化问题