-
-
Save spnow/4c3decba525c27ec755c873b1097795e to your computer and use it in GitHub Desktop.
pwnable.kr coins 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess | |
| import socket | |
| import sys | |
| N = 0 | |
| C = 0 | |
| left, right, mid = 0, 0, 0 | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| s.connect(("0.0.0.0", 9007)) | |
| while True: | |
| lines = s.recv(512).splitlines() | |
| for line in lines: | |
| if "expire" in line: | |
| break | |
| if not(line.isdigit() or line.startswith("N=")): | |
| print "|", line | |
| sys.stdout.flush() | |
| if line.startswith("N="): | |
| N = int(line[line.index("=") + 1: line.index(" ")]) | |
| C = int(line[line.rindex("=")+1:]) | |
| left = 0 | |
| right = N | |
| mid = right/2 + right%2 | |
| payload = " ".join(str(x) for x in range(left, mid)) + "\n" | |
| s.send(payload) | |
| if line.isdigit(): | |
| weight = int(line) | |
| if weight < (mid-left)*10: | |
| right = mid | |
| else: | |
| left = mid | |
| mid = left + (right-left)/2 + (right-left)%2 | |
| payload = " ".join(str(x) for x in range(left, mid)) + "\n" | |
| s.send(payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment