Search-0
CRYPTO EASY - 380
We are given the code to a python program and a container we can start which runs it
from Crypto.Util.number import getPrime, inverse, bytes_to_long
from string import ascii_letters, digits
from random import choice
m = open("flag.txt", "rb").read()
p = getPrime(128)
q = getPrime(128)
n = p * q
e = 65537
l = (p-1)*(q-1)
d = inverse(e, l)
m = pow(bytes_to_long(m), e, n)
print(m)
print(n)
p = "{0:b}".format(p)
for i in range(0,108):
print(p[i], end="")From what we can see in the code, this is a simple RSA chall.
What the code does is it generates the variables for an RSA encryption algorithm, but then leaks the first 108 bits of p.
What we need to do is loop over every number between the leaked number and the max 128 bit int and see if the number can divide n with a remainder of 0, if it can, we have p and can therefore decrypt
This script finds p, prints it and also prints q afterward.
Using these variables we can now easily decode the RSA. I personally used https://www.dcode.fr/rsa-cipher, it's my favorite.
Decode it and there you have the flag.
Last updated
Was this helpful?
