当前位置:网站首页>[RoarCTF2019]babyRSA威尔逊定理
[RoarCTF2019]babyRSA威尔逊定理
2022-07-27 21:07:00 【[email protected]】
1.题目代码
# import sympy
# import random
#
# def myGetPrime():
# A= getPrime(513)
# print(A)
# B=A-random.randint(1e3,1e5)
# print(B)
# return sympy.nextPrime((B!)%A)
# p=myGetPrime()
# #A1=21856963452461630437348278434191434000066076750419027493852463513469865262064340836613831066602300959772632397773487317560339056658299954464169264467234407
# #B1=21856963452461630437348278434191434000066076750419027493852463513469865262064340836613831066602300959772632397773487317560339056658299954464169264467140596
#
# q=myGetPrime()
# #A2=16466113115839228119767887899308820025749260933863446888224167169857612178664139545726340867406790754560227516013796269941438076818194617030304851858418927
# #B2=16466113115839228119767887899308820025749260933863446888224167169857612178664139545726340867406790754560227516013796269941438076818194617030304851858351026
#
# r=myGetPrime()
#
# n=p*q*r
# #n=85492663786275292159831603391083876175149354309327673008716627650718160585639723100793347534649628330416631255660901307533909900431413447524262332232659153047067908693481947121069070451562822417357656432171870951184673132554213690123308042697361969986360375060954702920656364144154145812838558365334172935931441424096270206140691814662318562696925767991937369782627908408239087358033165410020690152067715711112732252038588432896758405898709010342467882264362733
# c=pow(flag,e,n)
# #
# #c=75700883021669577739329316795450706204502635802310731477156998834710820770245219468703245302009998932067080383977560299708060476222089630209972629755965140317526034680452483360917378812244365884527186056341888615564335560765053550155758362271622330017433403027261127561225585912484777829588501213961110690451987625502701331485141639684356427316905122995759825241133872734362716041819819948645662803292418802204430874521342108413623635150475963121220095236776428
# #so,what is the flag?2.复现
直接分解p,q,r。发现可以分解。
import gmpy2
import libnum
import sympy
import math
n=85492663786275292159831603391083876175149354309327673008716627650718160585639723100793347534649628330416631255660901307533909900431413447524262332232659153047067908693481947121069070451562822417357656432171870951184673132554213690123308042697361969986360375060954702920656364144154145812838558365334172935931441424096270206140691814662318562696925767991937369782627908408239087358033165410020690152067715711112732252038588432896758405898709010342467882264362733
p=1276519424397216455160791032620569392845781005616561979809403385593761615670426423039762716291920053306063214548359656555809123127361539475238435285654851
q=5057572094237208127867754008134739503717927865750318894982404287656747895573075881186030840558129423864679886646066477437020450654848839861455661385205433
r=13242175493583584108411324143773780862426183382017753129633978933213674770487765387985282956574197274056162861584407275172775868763712231230219112670015751
c=75700883021669577739329316795450706204502635802310731477156998834710820770245219468703245302009998932067080383977560299708060476222089630209972629755965140317526034680452483360917378812244365884527186056341888615564335560765053550155758362271622330017433403027261127561225585912484777829588501213961110690451987625502701331485141639684356427316905122995759825241133872734362716041819819948645662803292418802204430874521342108413623635150475963121220095236776428
phi=(p-1)*(q-1)*(r-1)
e=0x1001
d=gmpy2.invert(e,phi)
m=pow(c,d,n)
flag=libnum.n2s(int(m))
print(flag)
# b'RoarCTF{wm-CongrAtu1ation4-1t4-ju4t-A-bAby-R4A}'但是这道题应该不是想考这个,应该是要我们用p,q,r的生成方式,算出p,q,r。
重点是sympy.nextPrime((B!)%A),B,A都知道,求出B!%A就可以了,但是直接算是不能算的,因为B太大了。
查了一下这里用威尔逊定理:(p-1)!+1=0 (mod p)。A,B很相近,而且A大于B,所以A!是包含B!的。
(B-1)!+1
0(mod B)
(A-1)!+1
0(mod A)->B!*(B+1)......(A-1)+1
0 mod A->B!*(B+1)......(A-1)
-1 mod A
故只要求出(B+1)(B+2)…*(A-1)在模数A下的逆(这里设为C1),即
B!≡-1*C1 (mod A),那么B!%A的值就可以求出
import gmpy2
import libnum
import sympy
A1=21856963452461630437348278434191434000066076750419027493852463513469865262064340836613831066602300959772632397773487317560339056658299954464169264467234407
B1=21856963452461630437348278434191434000066076750419027493852463513469865262064340836613831066602300959772632397773487317560339056658299954464169264467140596
A2=16466113115839228119767887899308820025749260933863446888224167169857612178664139545726340867406790754560227516013796269941438076818194617030304851858418927
B2=16466113115839228119767887899308820025749260933863446888224167169857612178664139545726340867406790754560227516013796269941438076818194617030304851858351026
n=85492663786275292159831603391083876175149354309327673008716627650718160585639723100793347534649628330416631255660901307533909900431413447524262332232659153047067908693481947121069070451562822417357656432171870951184673132554213690123308042697361969986360375060954702920656364144154145812838558365334172935931441424096270206140691814662318562696925767991937369782627908408239087358033165410020690152067715711112732252038588432896758405898709010342467882264362733
c=75700883021669577739329316795450706204502635802310731477156998834710820770245219468703245302009998932067080383977560299708060476222089630209972629755965140317526034680452483360917378812244365884527186056341888615564335560765053550155758362271622330017433403027261127561225585912484777829588501213961110690451987625502701331485141639684356427316905122995759825241133872734362716041819819948645662803292418802204430874521342108413623635150475963121220095236776428
e=0x1001
def getprime(A,B):
c=1
for i in range(B+1,A):
c=(c*gmpy2.invert(i,A))%A
c=c*(A-1)%A
return sympy.nextprime(c)
p=getprime(A1,B1)
q=getprime(A2,B2)
r=n//p//q
phi=(p-1)*(q-1)*(r-1)
d=gmd=gmpy2.invert(e,phi)
m=pow(c,d,n)
flag=libnum.n2s(int(m))
print(flag)
# b'RoarCTF{wm-CongrAtu1ation4-1t4-ju4t-A-bAby-R4A}'版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_61774705/article/details/124784597
边栏推荐
- Zabbix4.0 uses SNMP agent to monitor vcenter6.5
- In 2019, the world's top ten semiconductor manufacturers: Intel returned to the first place, and apple rose sharply against the trend
- The print version of imeta | international standard ISSN is officially confirmed, and the application for dual ISSN is completed
- Interviewer: let's talk about the specific process of network data transmission
- Technical certification | Tupo software and Huawei cloud create a new situation of win-win cooperation
- Zabbix4.0使用SNMP代理方式监控vcenter6.5
- JUC toolkit learning
- C # delegate usage -- console project, which implements events through delegation
- 字符流学习14.3
- 真的很难理解?RecyclerView 缓存机制到底是几级缓存?
猜你喜欢

给网站套上Cloudflare(以腾讯云为例)

Lua basic grammar learning
![[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters](/img/05/7029eb1fe36d7ddab2640f07247c81.png)
[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters

NDK series (6): let's talk about the way and time to register JNI functions
![[number recognition] recognize 0-9 numbers based on Hopfield neural network with matlab code](/img/10/de712b67a7538be03f8fb722271949.png)
[number recognition] recognize 0-9 numbers based on Hopfield neural network with matlab code

File&递归14.1

org.junit.runners.model.InvalidTestClassError: Invalid test class ‘com.zhj.esdemo.MysqlTests‘: 1.

突发,微信重要通知

29. Learn the stacked column chart of highcharts using percentage

The print version of imeta | international standard ISSN is officially confirmed, and the application for dual ISSN is completed
随机推荐
编辑复制粘贴判定问题(bug?),所见即所得显示符号问题反馈。
2019年全球十大半导体厂商:英特尔重回第一,苹果逆势大涨
为什么 Redis 集群要使用反向代理? 看这篇就明白了
详解分布式系统的幂等
Explain the idempotence of distributed system in detail
CaEGCN: Cross-Attention Fusion based Enhanced Graph Convolutional Network for Clustering 2021
Redis 哈希Hash底层数据结构
ELK日志分析系统安装和部署
NDK series (6): let's talk about the way and time to register JNI functions
Error:svn: E155010: ‘/Users/.../Desktop/wrokspace/xxx‘ is scheduled for addition, but is missing
How to use xshell Free Edition
In 2019, the world's top ten semiconductor manufacturers: Intel returned to the first place, and apple rose sharply against the trend
面试官问线程安全的List,看完再也不怕了!
为什么需要等待计时2MSL?
JUC工具包学习
The total investment is 60billion! Foxconn semiconductor high-end package test project officially settled in Qingdao
JS array copy speed test 220320
C # delegate usage -- console project, which implements events through delegation
Figure basic knowledge code
[signal denoising] signal denoising based on Kalman filter with matlab code
0(mod B)