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)
We’re provided the following values:
N = 77483692467084448965814418730866278616923517800664484047176015901835675610073e = 65537c = 43711206624343807006656378470987868686365943634542525258065694164173101323321For those of you who don’t know how RSA works, here’s a short explanation:
First, primes and are selected at random. These need to be rather large, and are typically 128, 256, or 512 bits. These primes are kept secret.
Then, is calculated. This is our modulus, and is publicly known. Because of how large and 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 . This is Euler’s totient. This is kept private, and, importantly can only be calculated by those who know the factorization of .
We can choose a public exponent value, , at this point. It is most commonly 65537. Importantly, e must be coprime to , because it is used to calculate the private exponent value, .
Essentially, it must hold true that . In other words, is the multiplicative inverse of over the modulus . We can find 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:
Where c is the ciphertext.
Here’s a quick explanation on why decryption works:
Note that because
Therefore,
According to Euler’s Theorem,
Thus,
Knowing all this, we can now take a look at provided source code. RSA relies on the inability of an attacker to feasibly factor . However, in this example, N seems rather small…
We can use this site to factor it in ~2 minutes. This provides us and , 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 = 77483692467084448965814418730866278616923517800664484047176015901835675610073e = 65537c = 43711206624343807006656378470987868686365943634542525258065694164173101323321
# https://www.alpertron.com.ar/ECM.HTMp = 1025252665848145091840062845209085931q = 75575216771551332467177108987001026743883
assert p*q == Nphi = (p-1)*(q-1) # calculate phid = inverse(e, phi) # the multiplicative inverse of e (mod phi)m = pow(c, d, N) # decryptionprint(m)print(long_to_bytes(m)) # convert the message to bytes (characters)Run the script to get the flag!
utflag{just_send_plaintext}