9oat's LAB
[Pwnable.kr] coin1 본문
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | from socket import * def parser(q): num = int(q.split('N=')[1].split(' C')[0]) cnt = int(q.split('C=')[1].split('\n')[0]) return num, cnt def value(src, dst): ans = ' '.join(str(i) for i in range(src, dst)) return ans def mid(src, dst): if (dst - src) % 2 == 0: mid = src + (dst-src) / 2 elif (dst - src) % 2 == 1: mid = src + (dst - src) / 2 + 1 else: mid = 1 return mid HOST = 'pwnable.kr' PORT = 9007 s = socket(AF_INET, SOCK_STREAM) s.connect((HOST, PORT)) print s.recv(2048) for i in range(0, 100): num, cnt = parser(s.recv(20)) print 'Coins :', num, ', Chances :', cnt, '\n' src = 0 dst = num w = 1 # first time for j in range(1, cnt + 1): if w % 10 == 0: src = dst dst = mid(src, tdst) else: tdst = dst dst = mid(src, tdst) s.send(value(src, dst) + '\n') print 'Chance :', j print 'Coin :', value(src, dst) w = int(s.recv(20)) print 'Weight : ', w, '\n' answer = int(value(src, dst)) if w == 10: answer = answer + 1 print 'Counterfeit coin is', answer s.send(str(answer) + '\n') print s.recv(20) print s.recv(200) # print flag | cs |
코딩은 가끔 해야 재밌다
'Write Up > Pwnable.kr' 카테고리의 다른 글
[Pwnable.kr] unlink (0) | 2017.08.27 |
---|---|
[Pwnable.kr] input (0) | 2017.07.16 |
Comments