from pwn import *
from Crypto.Util.number import *

base_hash = 105509268601419464273056214414138331937616184225244762627257868386725786436592

def int_to_base64(num):
	val = hex(num)[2:].replace("L","")
	if len(val) % 2 != 0:
		val = "0" + val
	val = val.decode("hex").encode("base64").replace("\n","")
	return val

flag = ""

r = process("./hm4c.sh")
r.recvline().replace("\n","")
for i in range(256):
	r.recvline().replace("\n","")
	r.recvline().replace("\n","")
	r.recvline().replace("\n","")
	r.sendline("1")
	r.recvline().replace("\n","")

	r.sendline(int_to_base64(1<<i))
	recvd = r.recvline().replace("\n","")
	if int(recvd) == base_hash:
		flag += "1"
	else:
		flag += "0"

flag = flag[::-1]
print "[+] Got the flag: ", long_to_bytes(int(flag,2))