Skip to content

Instantly share code, notes, and snippets.

@samueltangz
Created February 13, 2021 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samueltangz/da5b0ade1c1daddc7205a175456ff925 to your computer and use it in GitHub Desktop.
Save samueltangz/da5b0ade1c1daddc7205a175456ff925 to your computer and use it in GitHub Desktop.
from Crypto.Cipher import AES
import base64
import hashlib
from tqdm import tqdm
def main():
c = base64.b64decode('FEAjLtaf9bQ7oJCY53mV3IJOWDVi7donm6KEb9yjsxkCjuz0gpluD1vczeQGb8Pg')
for k in tqdm(range(2**32)):
key = (str(k).encode() + b'\0'*16)[:16]
cipher = AES.new(key, AES.MODE_ECB)
m = cipher.decrypt(c)
if b'kurenaifCTF' not in m: continue
print(k, m)
# kurenaifCTF{twice_reloaded_mersenne_twister}
if __name__ == '__main__':
main()
'''
key
The passphrase. If the passphrase is shorted than expected, it is silently padded with NUL characters; if the passphrase is longer than expected, it is silently truncated.
'''
'''
❯ pypy3 05-three-values-twister.py
7%|█▌ | 296322353/4294967296 [21:45<5:47:51, 191583.84it/s]
296332286 b'kurenaifCTF{twice_reloaded_mersenne_twister}\x04\x04\x04\x04'
8%|█▊ | 346303052/4294967296 [25:44<4:18:03, 255016.83it/s]
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment