攻防世界:https://adworld.xctf.org.cn/
题目:二元一次方程组 (NO.GFSJ1112)
题点:RSA密码体制
题解:Python代码
import libnum
# extended euclidean algorithm
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)
# modular multiplicative inverse
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
n = 5700102857084805454304483466349768960970728516788155745115335016563400814300152521175777999545445613444815936222559357974566843756936687078467221979584601
avg = 75635892913589759545076958131039534718834447688923830032758709253942408722875
c = 888629627089650993173073530112503758717074884215641346688043288414489462472394318700014742820213053802180975816089493243275025049174955385229062207064503
e = 65537
phi_n = n - 2*avg + 1 # phi(n) = (p-1)(q-1) = pq-(p+q)+1
d = modinv(e, phi_n) # de = 1 mod phi_n, d = e^-1 mod phi_n
m = pow(c, d, n)
print(libnum.n2s(m))
输出:
b'hsctf{Dl3F4TH3rRR4iin_AvAvA}'