当前位置:网站首页>[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
边栏推荐
- 并发和并行有什么区别?
- 加速IGBT国产化!比亚迪半导体将独立上市,市值或达300亿元!
- 台积电3nm细节曝光:晶体管密度高达2.5亿个/mm²,性能及能效大幅提升
- NDK series (6): let's talk about the way and time to register JNI functions
- Common Taylor expansion
- Key points of data management
- The technology of applet container is very promising, which can greatly improve the efficiency of mobile R & D
- 【C语言】通讯录(动态版本)
- urllib.error. URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: un
- Arm32 for remote debugging
猜你喜欢
随机推荐
MySQL之数据查询(WHERE)
Character stream learning 14.3
Error:svn: E155010: ‘/Users/.../Desktop/wrokspace/xxx‘ is scheduled for addition, but is missing
[December Haikou] the 6th International Conference on ships, marine and Maritime Engineering in 2022 (naome 2022)
编辑复制粘贴判定问题(bug?),所见即所得显示符号问题反馈。
Shuffle, partition and read of tfrecord
reduce错误示范
My annual salary is 1million, and I don't have clothes more than 100 yuan all over my body: saving money is the top self-discipline
Design and implementation of spark offline development framework
主数据管理理论与实践
Those "experiences and traps" in the data center
Which one is better to request to merge -- three skills of interface request merging, and the performance directly explodes the table
Apple releases new iPhone se: equipped with A13 bionic processor, priced from 3299 yuan
Flutter pull_ to_ refresh-1.6.0/lib/src/internals/slivers. dart:164:13: Error: Method not found: ‘descr
File&递归14.1
Calling dht11/22 temperature and humidity sensor in Proteus simulation Arduino
Redis 哈希Hash底层数据结构
台积电3nm细节曝光:晶体管密度高达2.5亿个/mm²,性能及能效大幅提升
【12月海口】2022年第六届船舶,海洋与海事工程国际会议(NAOME 2022)
Spark 离线开发框架设计与实现
0(mod B)








