from Crypto.Util.number import inverse, long_to_bytes, bytes_to_long
from Crypto.PublicKey import RSA
from factordb.factordb import FactorDB
with open("pubkey.pem","r") as f1, open("flag.enc", "rb") as f2:
key = RSA.import_key(f1.read())
c = bytes_to_long(f2.read())
#--------FactorDB--------#
factors = f.get_factor_list()
#--------Rabin Cryptosystem--------#
m_p = pow(c, (p + 1) // 4, p)
m_q = pow(c, (q + 1) // 4, q)
a = (inv_p * p * m_q + inv_q * q * m_p) % N
c = (inv_p * p * m_q - inv_q * q * m_p) % N
plaintext_list = [a, b, c, d]
for plaintext in plaintext_list:
s = str(hex(plaintext))[2:]