BabyRSA(私钥读取+乱码密文2进制读取后字节转长整数)

题目:

密文打开时乱码

私钥

from gmpy2 import *
from sympy import factorint
from Crypto.PublicKey import RSA
from Crypto.Util.number import *

f = open(r"C:\Temp\202012CRYPTO_PolarDN_CTF_BabyRSA\private.key").read()
pub_key = RSA.importKey(f)
d = pub_key.d
e = pub_key.e
n = pub_key.n
p = pub_key.p
q = pub_key.q
print("n>>>", n, "d>>>", d, "e>>>", e, "p>>>", p, "q>>>", q, sep="\n")
c = open(r"C:\Temp\202012CRYPTO_PolarDN_CTF_BabyRSA\flag.txt", "rb").read()
c = bytes_to_long(c)
m = pow(c, d, n)
print(long_to_bytes(m))


posted @ 2025-05-02 22:05  lethe311  阅读(2)  评论(0)    收藏  举报