from pwn import *

def _register(r, username):
    r.recvuntil("choice: ")
    r.sendline("1")
    r.recvuntil("register: ")
    r.sendline("bdmin")
    cookie = r.recvline().strip()[len("[+] Here, take your cookie:  "):]
    return cookie

def _login(r, cookie):
    r.recvuntil("choice: ")
    r.sendline("2")
    r.recvuntil("cookie: ")
    r.sendline(cookie)
    return r.recvline().strip()

if __name__ == "__main__":
    r = remote("13.233.196.46", 1337)

    cookie = _register(r, "admix").decode("hex")
    cookie = cookie[:13] + chr(ord(cookie[13]) ^ ord('x') ^ ord('n')) + cookie[14:]
    cookie = cookie.encode("hex")
    r.close()

    r = remote("13.233.196.46", 1337)
    print _login(r, cookie)
