PWNABLE——coin1

coding题目。思路是二分法。不多赘述。

from pwn import *
import pwnlib
import time
local = 0
if local:
    p = process("./333")
else:
    p = remote("pwnable.kr",9007)
for i in range(31):
    print p.recvline()
while True:
    n_c = p.recvline()
    print n_c  
    # 所有验证通过,进入交互状态
    if 'N=' not in n_c:
        p.interactive()
    n_c = n_c.split(' ')
    n = int(n_c[0][2:])
    c = int(n_c[1][2:])
    print n,c
    # 特别处理N=1,C=0的情况
    if n == 1:
        p.sendline('0')
        print p.recvline()
        continue
    data = range(n)
    for i in range(c)[::-1]:
        if len(data) > 2**i:
            data1 = data[0:2**i]
            data2 = data[2**i:]
            p.sendline(' '.join([str(j) for j in data1]))
            #print ' '.join([str(j) for j in data1])
            weight = int(p.recvline())
            #print weight
            if weight == (2**i)*10:
                data = data2
            else:
                data = data1
            if i == 0:
                print data[0]
                p.sendline(str(data[0]))
                res = p.recvline()
                print res
                # 这里用于处理chance过多的情况
                while 'Correct!' not in res:
                    p.sendline(str(data[0]))
                    res = p.recvline()
                    print res

你可能感兴趣的:(PWNABLE——coin1)