当前位置:网站首页>[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
边栏推荐
猜你喜欢
随机推荐
三次握手的Socket交互流程
【12月海口】2022年第六届船舶,海洋与海事工程国际会议(NAOME 2022)
Application of user portrait in precise push of wechat official account of scientific journals
This is the most concise guide to tcpdump in history. It's enough to read this one
Technical certification | Tupo software and Huawei cloud create a new situation of win-win cooperation
Join hands with Changjiang storage, jiangbolong launches the world's smallest expansion card
ZCMU--1720: 死亡如风,我要装逼
Zabbix4.0使用SNMP代理方式监控vcenter6.5
如果我们是那晚负责修复 B 站崩了的开发人员
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
JS array copy speed test 220320
The technology of applet container is very promising, which can greatly improve the efficiency of mobile R & D
2022夏暑假每日一题(五)
实现按照序号命名的txt文件由后往前递补重命名文件
你的列表很卡?这4个优化能让你的列表丝般顺滑
总投资600亿!富士康半导体高端封测项目正式落户青岛
Which one is better to request to merge -- three skills of interface request merging, and the performance directly explodes the table
Lua基础语法学习
钉钉报警工具
NDK series (6): let's talk about the way and time to register JNI functions
0(mod B)![[C language] address book (dynamic version)](/img/29/3df19c187bee31ee4671e12d7cc7ff.jpg)








