题目文件
from Crypto.Util.number import *
flag = b''
m = bytes_to_long(flag)
p = getPrime(128)
q = getPrime(128)
phi = (p - 1) * (q - 1)
n = p * q
e = 65537
c = pow(m, e, n)
print(f"n: {n}")
print(f"e: {e}")
print(f"c: {c}")
'''
n: 82262302255673546896068943571445089014908011317331238957390324506176165692353
e: 65537
c: 74363314827014337197228165426657527588061111803487873351317699624723182579082
'''
操作内容:
该题目属于已知n、e、密文c,求明文。
n值可以通过分解质因数得到p、q值。
使用yafu分解工具
将n值存入txt文档内
注意:
(1)n为十进制
(2)txt文件结尾必须有一个换行符,如下图:
(3)该命令会删除这个txt,请注意保存。
使用分解命令 yafu-x64 "factor(@)" -batchfile 1.txt
得到p、q值如下
解题代码
from Crypto.Util.number import *
from gmpy2 import *
p = 295550294274400439200910843028567835583
q = 278336052608690728674410932689178712191
n = 82262302255673546896068943571445089014908011317331238957390324506176165692353
e = 65537
c = 74363314827014337197228165426657527588061111803487873351317699624723182579082
phi = (p-1) * (q-1)
d = inverse(e, phi)
m = pow(c, d, n)
print(long_to_bytes(m))
标签:phi,RSA,明文,密文,print,import,txt From: https://www.cnblogs.com/Cyruswong/p/18321628