easy peasy
This commit is contained in:
51
easy_peasy/otp.py
Executable file
51
easy_peasy/otp.py
Executable file
@@ -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)
|
||||
32
easy_peasy/sol.py
Executable file
32
easy_peasy/sol.py
Executable file
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user