Logo
RSA 256

RSA 256

April 1, 2024
2 min read

Based on the military-grade encryption offered by AES-256, RSA-256 will usher in a new era of cutting-edge security… or at least, better security than RSA-128.

By Jeriah (@jyu on discord)

vals.txt


We’re provided the following values:

N = 77483692467084448965814418730866278616923517800664484047176015901835675610073
e = 65537
c = 43711206624343807006656378470987868686365943634542525258065694164173101323321

For those of you who don’t know how RSA works, here’s a short explanation:

First, primes pp and qq are selected at random. These need to be rather large, and are typically 128, 256, or 512 bits. These primes are kept secret.

Then, N=pqN=pq is calculated. This is our modulus, and is publicly known. Because of how large pp and qq are, this should be infeasible to calculate on classical computers (quantum computers are a whole different story, but they’re not quite there yet). We also calculate ϕ(N)=(p1)(q1)\phi (N)=(p-1)(q-1). This is Euler’s totient. This is kept private, and, importantly can only be calculated by those who know the factorization of NN.

We can choose a public exponent value, ee, at this point. It is most commonly 65537. Importantly, e must be coprime to ϕ(N)\phi (N), because it is used to calculate the private exponent value, dd.

Essentially, it must hold true that ed1  (mod  ϕ(N))ed \equiv 1\;(mod\; \phi (N)). In other words, dd is the multiplicative inverse of ee over the modulus ϕ(N)\phi (N). We can find dd via the Extended Euclidean Algorithm. I won’t include it here, but if you’re interested, look it up!

Then, encryption and decryption occur as follows, respectively:

mec  (mod  N)m^e \equiv c\; (mod\; N)
Where c is the ciphertext.
cdm  (mod  N)c^d \equiv m\; (mod\; N)

Here’s a quick explanation on why decryption works:

cdmed  (mod  N)c^d \equiv m^{ed}\;(mod\;N)
Note that ed=kϕ(N)+1ed = k\phi (N) + 1 because ed1  (mod  ϕ(N))ed \equiv 1\;(mod\; \phi (N))
Therefore,
med  (mod  N)mkϕ(N)+1  (mod  N)m^{ed}\;(mod\;N) \equiv m^{k\phi (N) + 1}\;(mod\;N)

According to Euler’s Theorem,
mkϕ(N)1  (mod  N)m^{k\phi (N)} \equiv 1\;(mod\;N)

Thus,
mkϕ(N)+1mkϕ(N)mm  (mod  N)m^{k\phi (N) + 1} \equiv m^{k\phi (N)} \cdot m \equiv m\;(mod\;N)

Knowing all this, we can now take a look at provided source code. RSA relies on the inability of an attacker to feasibly factor NN. However, in this example, N seems rather small…

We can use this site to factor it in ~2 minutes. This provides us pp and qq, and through the same process I just described for encryption and decryption, we can do this easily in Python, utilizing the Pycryptodome module!

from Crypto.Util.number import *
N = 77483692467084448965814418730866278616923517800664484047176015901835675610073
e = 65537
c = 43711206624343807006656378470987868686365943634542525258065694164173101323321
# https://www.alpertron.com.ar/ECM.HTM
p = 1025252665848145091840062845209085931
q = 75575216771551332467177108987001026743883
assert p*q == N
phi = (p-1)*(q-1) # calculate phi
d = inverse(e, phi) # the multiplicative inverse of e (mod phi)
m = pow(c, d, N) # decryption
print(m)
print(long_to_bytes(m)) # convert the message to bytes (characters)

Run the script to get the flag!

utflag{just_send_plaintext}
t>
o:after-swap', ensureKatexStyles)