This challenge is about a variant of RSA encryption where the integers are replaced by a polynomial ring over
Recall that RSA works in a ring
In this challenge,
The crucial observation now is that factoring polynomials over finite fields is easy, hence we can split
Now since babyrsa
:
#!/usr/bin/env sage
import re
from pubkey import P,n,e
R.<a> = GF(2**2049)
c_int = Integer(open('flag.enc','rb').read().encode('hex'), 16)
c_poly = P(R.fetch_int(c_int))
(g,_), (h,_) = factor(n)
phi = (2**g.degree() - 1) * (2**h.degree() - 1)
d = ZZ(Mod(e,phi)**-1)
m_poly = pow(c_poly, d, n)
m_int = R(m_poly).integer_representation()
m = format(m_int, '0256x').decode('hex')
for flag in re.findall(b'flag{[^}]+}', m):
print(flag)
This sage
script prints the flag:
$ ./pwn.sage
flag{P1ea5e_k33p_N_as_A_inTegeR~~~~~~}
$