Created
April 12, 2020 19:09
-
-
Save obormot/e4b3dc669a5d669bc793b1c606cca854 to your computer and use it in GitHub Desktop.
cryptohack.org/challenges
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # py2 | |
| import socket, json | |
| conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| conn.connect(('socket.cryptohack.org', 13372)) | |
| conn.recv(100) # "Gotta go fast!" | |
| # OTP key len is 32 bytes (sha256 digest) | |
| # by using all zeroes for input we don't need to de-XOR the key | |
| input_data = '00' * 32 | |
| data = {'option': 'encrypt_data', 'input_data': input_data} | |
| conn.send(json.dumps(data) + '\n') | |
| resp = json.loads(conn.recv(1024)) | |
| print resp | |
| key = resp['encrypted_data'].decode('hex') | |
| # get encrypted flag | |
| data = {'option': 'get_flag'} | |
| conn.send(json.dumps(data) + '\n') | |
| resp = json.loads(conn.recv(1024)) | |
| print resp | |
| flag = resp['encrypted_flag'].decode('hex') | |
| # decrypt flag | |
| print ''.join(chr(ord(f) ^ ord(k)) for f, k in zip(flag, key)) | |
| conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment