0x01 题目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import libnum
from Crypto.Util import number
from functools import reduce
from secret import flag

n = 5
size = 64
while True:
ps = [number.getPrime(size) for _ in range(n)]
if len(set(ps)) == n:
break

e = 65537
n = reduce(lambda x, y: x*y, ps)
m = libnum.s2n(flag)
c = pow(m, e, n)

print('n = %d' % n)
print('c = %d' % c)
1
2
n = 175797137276517400024170861198192089021253920489351812147043687817076482376379806063372376015921
c = 144009221781172353636339988896910912047726260759108847257566019412382083853598735817869933202168

0x02 解题

从题目中的:

1
2
3
4
5
6
n = 5
size = 64
while True:
ps = [number.getPrime(size) for _ in range(n)]
if len(set(ps)) == n:
break

可以看出n是由5组素数相乘组成的

factordb.com大数分解

得到:

1
n = 9401433281508038261*10252499084912054759*11215197893925590897*11855687732085186571*13716847112310466417

即:

1
2
3
4
5
6
7
8
9
10
from Crypto.Util.number import *
e = 65537
n = 175797137276517400024170861198192089021253920489351812147043687817076482376379806063372376015921
c = 144009221781172353636339988896910912047726260759108847257566019412382083853598735817869933202168
p1 = 9401433281508038261
p2 = 10252499084912054759
p3 = 11215197893925590897
p4 = 11855687732085186571
p5 = 13716847112310466417
assert n == p1*p2*p3*p4*p5

assert检测通过

再由:
$$
\phi(n) = (p_1-1)\cdot(p_2-1)\cdot(p_3-1)\cdot(p_4-1)\cdot(p_5-1)
$$
最后:

1
2
3
4
5
phi = (p1-1)*(p2-1)*(p3-1)*(p4-1)*(p5-1)
from gmpy2 import invert
d = invert(e,phi)
m = pow(c,d,n)
long_to_bytes(m)

得到flag:

image-20221019195612672