script does rsa but uses a power of 2 instead of a normal e, and uses a prime as n.
so, basically it does pow(pt,2**64,p)
this is somewhat reversible, since we can take the modular square root of the ct repeatedly until we get our plaintext.
one problem though - there are 2 modular square roots
this means that we would potentially have to go through 2**64 roots in order to get the correct one
we can reduce this significantly by finding the "pseudo-phi", which we can just use Crypto.Util.number's inverse for
this finds pow(pt,2**30,p)
this is significantly lower, and this is feasible to bruteforce
i didnt solve so i dont have script but uhhhhhh yeah
The binary forms an interactive 100-byte printf prompt, where every input has printf called on it directly. No protections, so we can execute a simple GOT overwrite attack. Firstly, we'll need to leak libc - this can be done by leaking __libc_start_main_ret at offset 39. Then, we can use a format string payload to overwrite printf@got with system. Afterwards, everything we enter into the prompt will be system'd, forming a sort of shell. We can type /bin/sh and hit enter to get into a proper shell with this, or just enjoy the existing one. we cat flag.txt to get the flag.
From the script, we can produce the following equations e1 * d = 1 mod phi e2 * (d + 2) = 1 mod phi
Rearranging e1 * d = 1 mod phi e2 * d + e2 * 2) = 1 mod phi
Then, we subtract e2*2 from 1 to get e1 * d = 1 mod phi e2 * d = some negative number
We then can do a trick I learnt from FwordCTF (kinda)
We multiply both equations by the opposite value to get
e1 * d * e2 = e2 e1 * e2 * d = some negative number * e1
Now we know that these are both the same, so we can simply subtract them from each other to get a multiple of phi.
If we know k*phi, we can just use that as phi, since that will still work. We use this then to get the flag.
Solve script below.