from pwn import *
import string

r = remote("crypto.chal.csaw.io","1578")
plaintext = ""
blocksize = 16
for k in range(2):
    b = ""
    for i in range(1,17):
        string_sent = "a"*(16-i)

        r.recv()
        r.sendline(string_sent)
        g1 = r.recvuntil("\n")[16:-1]
        g1 = g1[:32+k*32]
        print "String sent: ",string_sent
        for j in range(256):
            r.recv()
            r.sendline(string_sent + plaintext + b + chr(j))
            g2 = r.recvuntil("\n")[16:-1]
            g2 = g2[:32+k*32]
            if g1 == g2 and chr(j) in string.printable and j!=10 and j!=0:
                print chr(j), j
                b += chr(j)
                break
    plaintext += b
    print plaintext
