Skip to content

Instantly share code, notes, and snippets.

Created December 11, 2011 16:13
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 anonymous/1461329 to your computer and use it in GitHub Desktop.
Save anonymous/1461329 to your computer and use it in GitHub Desktop.
Rape the Hangman Scoreboard
require 'sinatra'
require 'iconv'
def hm_rape(name)
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
url = 'http://www.fun-with-words.com/hangman.html'
html = ic.iconv(`curl -s #{url}` << ' ')[0..-2]
data = html.scan(/hx=(.+?)#.+?GameKey" value="(\d+)"/m)[0]
post = 'HMState=play&HMWordCat=country&HMGameKey=' + data[1]
html = ic.iconv(`curl -s -d "#{post}" #{url}?hx=#{data[0]}` << ' ')[0..-2]
countries = open('countries.txt').read.downcase
guessed = ' '
while !html.include?('Congratulations!')
return hm_rape(name) if html.include?('Oops!')
puzzle = (html.scan(/ve';">(.+?)</) * '').gsub('&nbsp;', '.').downcase
cands = countries.scan(%r(^#{puzzle}$))
return hm_rape(name) if cands.size == 0
pot = (cands * '').split(//).find_all { |l| !guessed.include?(l) }
best = pot.sort { |x, y| pot.count(x) <=> pot.count(y) }[-1]
hx = html.scan(/hx=(.+?)#/) * ''
params = html.scan(/hidden" name="(.+?)" value="(.*?)"/)
qs = params.map { |p| p * '=' } * '&' + '&HMLetPick=' + best.upcase
html = ic.iconv(`curl -s -d "#{qs}" #{url}?hx=#{hx}` << ' ')[0..-2]
guessed += best
end
hx = html.scan(/hx=(.+?)#/) * ''
params = html.scan(/hidden" name="(.+?)" value="(.*?)"/)
qs = params.map { |p| p * '=' } * '&' + '&HMWinnerName=' + name
`curl -s -d "#{qs}" #{url}?hx=#{hx}`
return
end
get '/rape/:name' do
hm_rape(params[:name])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment