Easy Peasy
Problem
A one-time pad is unbreakable, but can you manage to recover the flag? (Wrap with picoCTF{}) nc mercury.picoctf.net 20266 otp.py
Solution
As stated in the description, this is a one-time pad challenge. One of the criteria of a one-time pad is that the key is never reused in part or in whole. We can modify the program so that it does not meet this requirement.
The significant bug in the otp.py script appears on lines 34-36:
if stop >= KEY_LEN: stop = stop % KEY_LEN key = kf[start:] + kf[:stop]stopequals the previous ending point of the key plus the length of the new user input. However, ifstopis greater than the key length,stopis set tostop % KEY_LEN. Thus, inputting just enough text to get to the end of the keyfile will setstopto 0 because40000 % 40000is0.key_locationis then set tostopandkey_locationis returned. So, when we input the next string to be encrypted theencryptfunction will receivekey_location=0, thus allowing us to use the same key that was used to encrypt the flag.Generate a
pwntoolstemplate withpwn template --host mercury.picoctf.net --port 20266 otp.py.The solve script is commented and explains the solution. In brief, since we know a clear text message and an encrypted message, we can find the key (as explained in this Computer Science StackExchange answer) and then decrypt the flag.
Flag
picoCTF{99072996e6f7d397f6ea0128b4517c23}
Last updated
Was this helpful?