当前位置:网站首页>【zer0pts CTF 2022】 Anti-Fermat
【zer0pts CTF 2022】 Anti-Fermat
2022-07-27 23:53:00 【[email protected]】
1. subject
from Crypto.Util.number import isPrime, getStrongPrime
from gmpy import next_prime
from secret import flag
# Anti-Fermat Key Generation
p = getStrongPrime(1024)
q = next_prime(p ^ ((1<<1024)-1))
n = p * q
e = 65537
# Encryption
m = int.from_bytes(flag, 'big')
assert m < n
c = pow(m, e, n)
print('n = {}'.format(hex(n)))
print('c = {}'.format(hex(c)))
#n = 0x1ffc7dc6b9667b0dcd00d6ae92fb34ed0f3d84285364c73fbf6a572c9081931be0b0610464152de7e0468ca7452c738611656f1f9217a944e64ca2b3a89d889ffc06e6503cfec3ccb491e9b6176ec468687bf4763c6591f89e750bf1e4f9d6855752c19de4289d1a7cea33b077bdcda3c84f6f3762dc9d96d2853f94cc688b3c9d8e67386a147524a2b23b1092f0be1aa286f2aa13aafba62604435acbaa79f4e53dea93ae8a22655287f4d2fa95269877991c57da6fdeeb3d46270cd69b6bfa537bfd14c926cf39b94d0f06228313d21ec6be2311f526e6515069dbb1b06fe3cf1f62c0962da2bc98fa4808c201e4efe7a252f9f823e710d6ad2fb974949751
#c = 0x60160bfed79384048d0d46b807322e65c037fa90fac9fd08b512a3931b6dca2a745443a9b90de2fa47aaf8a250287e34563e6b1a6761dc0ccb99cb9d67ae1c9f49699651eafb71a74b097fc0def77cf287010f1e7bd614dccfb411cdccbb84c60830e515c05481769bd95e656d839337d430db66abcd3a869c6348616b78d06eb903f8abd121c851696bd4cb2a1a40a07eea17c4e33c6a1beafb79d881d595472ab6ce3c61d6d62c4ef6fa8903149435c844a3fab9286d212da72b2548f087e37105f4657d5a946afd12b1822ceb99c3b407bb40e21163c1466d116d67c16a2a3a79e5cc9d1f6a1054d6be6731e3cd19abbd9e9b23309f87bfe51a822410a622. Reappear
The key to see p,q How to generate ,p Is random 1024 Bitprime number ,q = next_prime(p ^ ((1<<1024)-1)).
1<<1024-1=2**1024-1 Into 2 Hexadecimal is 1024 individual 1, Because of a binary XOR 1 Is to take its inverse , It means 1 become 0,0 become 1. therefore p^2**1024-1 Result x It's a p Every bit of is reversed , therefore x+p=2**1024-1.
because q yes x So q=x+r, Take it in p+q=2**1024-1+r, therefore p+q It's about equal to 2**1024.
And because of
hold p+q Take it in
therefore 4n=2**2048-(p-q)**2,p-q=
, because p+q=
, therefore p=
Then blast back p That's it .
import gmpy2
import sympy
import libnum
n = int(0x1ffc7dc6b9667b0dcd00d6ae92fb34ed0f3d84285364c73fbf6a572c9081931be0b0610464152de7e0468ca7452c738611656f1f9217a944e64ca2b3a89d889ffc06e6503cfec3ccb491e9b6176ec468687bf4763c6591f89e750bf1e4f9d6855752c19de4289d1a7cea33b077bdcda3c84f6f3762dc9d96d2853f94cc688b3c9d8e67386a147524a2b23b1092f0be1aa286f2aa13aafba62604435acbaa79f4e53dea93ae8a22655287f4d2fa95269877991c57da6fdeeb3d46270cd69b6bfa537bfd14c926cf39b94d0f06228313d21ec6be2311f526e6515069dbb1b06fe3cf1f62c0962da2bc98fa4808c201e4efe7a252f9f823e710d6ad2fb974949751)
c = int(0x60160bfed79384048d0d46b807322e65c037fa90fac9fd08b512a3931b6dca2a745443a9b90de2fa47aaf8a250287e34563e6b1a6761dc0ccb99cb9d67ae1c9f49699651eafb71a74b097fc0def77cf287010f1e7bd614dccfb411cdccbb84c60830e515c05481769bd95e656d839337d430db66abcd3a869c6348616b78d06eb903f8abd121c851696bd4cb2a1a40a07eea17c4e33c6a1beafb79d881d595472ab6ce3c61d6d62c4ef6fa8903149435c844a3fab9286d212da72b2548f087e37105f4657d5a946afd12b1822ceb99c3b407bb40e21163c1466d116d67c16a2a3a79e5cc9d1f6a1054d6be6731e3cd19abbd9e9b23309f87bfe51a822410a62)
e = 65537
p=(gmpy2.iroot(pow(2,2048)-4*n,2)[0]+pow(2,1024))//2
# p=(2**1024+gmpy2.iroot((2**1024)**2-4*n,2)[0])//2
p=int(p)
while(1):
p=sympy.nextprime(p)
if(n%p==0):
print(p)
break
q=n//p
phi=(p-1)*(q-1)
d=gmpy2.invert(e,phi)
m=pow(c,d,n)
flag=libnum.n2s(int(m))
print(flag)
# b'Good job! Here is the flag:\n+-----------------------------------------------------------+\n| zer0pts{F3rm4t,y0ur_m3th0d_n0_l0ng3r_w0rks.y0u_4r3_f1r3d} |\n+-----------------------------------------------------------+'
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/208/202207272106550047.html
边栏推荐
- 消息队列常见的几种使用场景介绍
- Unity 实现简单画板画画功能(笔记)
- Zabbix4.0 uses SNMP agent to monitor vcenter6.5
- Realization of gobang man-machine combat
- TSMC 3nm detail exposure: transistor density as high as 250million /mm ², Greatly improved performance and energy efficiency
- Remotely debug idea, configure remote debug, and add JVM startup parameter -xdebug in the program of remote server
- [C language] address book (dynamic version)
- 加速IGBT国产化!比亚迪半导体将独立上市,市值或达300亿元!
- Accelerate IGBT localization! BYD semiconductor will be listed independently, with a market value of 30billion yuan!
- Smartrefresh nested multiple recycleview sliding conflicts and incomplete layout display
猜你喜欢

TOGAF10标准读书会首场活动圆满举办,精彩时刻回顾!

Monologue of a software Investor: why don't I pursue fast-growing companies

File & recursion 14.1
![[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

Explain the idempotence of distributed system in detail

字符流学习14.3

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

Redis 哈希Hash底层数据结构

五子棋人机对战实现

Latex常用总结(2):输入矩阵(输入矩阵、对角阵、方程组等)
随机推荐
File & recursion 14.1
BUU-CTF basic rsa
[NCTF2019]babyRSA1
基于mediapipe的姿态识别和简单行为识别
Comparison between virtual memory and cache
Put cloudflare on the website (take Tencent cloud as an example)
Shuffle, partition and read of tfrecord
Control mode of CPU
Unity 实现简单画板画画功能(笔记)
[ACTF新生赛2020]crypto-aes
Latex中如何加粗字体 & 如何打出圆圈序号
Flutter pull_ to_ refresh-1.6.0/lib/src/internals/slivers. dart:164:13: Error: Method not found: ‘descr
Socket interaction process of three handshakes
2022/7/24-7/25
Those "experiences and traps" in the data center
五子棋人机对战实现
Edit the copy and paste judgment problem (bug?), WYSIWYG display symbol problem feedback.
BUUCTF-childRSA费马小定理
15million per day! BYD masks won a US $1billion order in California
Binary conversion method
hold p+q Take it in 
, because p+q=
, therefore p=