diff --git a/easy_peasy/otp.py b/easy_peasy/otp.py new file mode 100755 index 0000000..a598d74 --- /dev/null +++ b/easy_peasy/otp.py @@ -0,0 +1,51 @@ +#!/usr/bin/python3 +import os.path + +KEY_FILE = "key" +KEY_LEN = 50000 +FLAG_FILE = "flag" + + +def startup(key_location): + flag = open(FLAG_FILE).read() + kf = open(KEY_FILE, "rb").read() + + start = key_location + stop = key_location + len(flag) + + key = kf[start:stop] + key_location = stop + + result = list(map(lambda p, k: "{:02x}".format(ord(p) ^ k), flag, key)) + print("This is the encrypted flag!\n{}\n".format("".join(result))) + + return key_location + +def encrypt(key_location): + ui = input("What data would you like to encrypt? ").rstrip() + if len(ui) == 0 or len(ui) > KEY_LEN: + return -1 + + start = key_location + stop = key_location + len(ui) + + kf = open(KEY_FILE, "rb").read() + + if stop >= KEY_LEN: + stop = stop % KEY_LEN + key = kf[start:] + kf[:stop] + else: + key = kf[start:stop] + key_location = stop + + result = list(map(lambda p, k: "{:02x}".format(ord(p) ^ k), ui, key)) + + print("Here ya go!\n{}\n".format("".join(result))) + + return key_location + + +print("******************Welcome to our OTP implementation!******************") +c = startup(0) +while c >= 0: + c = encrypt(c) diff --git a/easy_peasy/sol.py b/easy_peasy/sol.py new file mode 100755 index 0000000..2e8581c --- /dev/null +++ b/easy_peasy/sol.py @@ -0,0 +1,32 @@ +#!/home/maxime/.pyvenv/bin/python3 +from pwn import * +import binascii + +buffersize = 50000-32 + +conn = remote("mercury.picoctf.net", 36981) +conn.recvline() +conn.recvline() + +encrypted_flag = conn.recvline().strip() + +conn.recvuntil(b'?') + +conn.sendline(b'0' * buffersize) + +conn.recvuntil(b'?') + +conn.sendline(b'0' * 32) + +conn.recvline() + +encrypted_0s = conn.recvline().strip() + +conn.close() + +encrypted_flag = binascii.unhexlify(encrypted_flag) +encrypted_0s = binascii.unhexlify(encrypted_0s) +for i in range(32): + print(chr(encrypted_0s[i] ^ encrypted_flag[i] ^ ord('0')), end='') +print() +