Rivest Shamir Adleman

点击此处获得更好的阅读体验


WriteUp来源

https://dunsp4rce.github.io/csictf-2020/crypto/2020/07/18/Rivest-Shamir-Adleman.html

by anishbadhri

题目描述

These 3 guys encrypted my flag, but they didn't tell me how to decrypt it.

题目考点

解题思路

The values of n is generated using a small prime. One of the primes can be searched using brute-force and the message can then be decrypted.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import mod
f = open("enc.txt").read().split('\n')
n = int(f[0].split()[2])
e = int(f[1].split()[2])
c = int(f[2].split()[2])
p = None
for i in range(2,n):
if n % i == 0:
p = i
break
q = n // p
phi = (p-1) * (q-1)
em = mod.Mod(e, phi)
d = int(1 // em)
cm = mod.Mod(c, n)
dec = int(cm ** d)
print(bytes.fromhex(hex(dec)[2:]))

Flag

1
csictf{sh0uld'v3_t4k3n_b1gg3r_pr1m3s}