Created
December 11, 2011 16:13
-
-
Save anonymous/1461329 to your computer and use it in GitHub Desktop.
Rape the Hangman Scoreboard
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 '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(' ', '.').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