Last active
August 29, 2015 14:05
-
-
Save epitron/bf844793bd7cc21c9212 to your computer and use it in GitHub Desktop.
Figlet-based CAPTCHA breaker (for IRC bots) -- accelerated!
This file contains hidden or 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 'epitools' | |
figlet_left = File.readlines('./figlet.input') | |
def get_first_char(i, arr) | |
arr.map { |x| x[0..i] } | |
end | |
def remove_first_char(i, arr) | |
arr.map { |x| x.slice(i..-1) } | |
end | |
def find_figlet(arr) | |
'A'.upto('Z').detect do |l| | |
`figlet -f big -w 11 #{l}`.split("\n").reject {|x| x.strip.empty?} == arr | |
end | |
end | |
time { | |
res = '' | |
while !figlet_left.map(&:strip).reject(&:empty?).empty? do | |
i = 5 | |
while !(x = find_figlet(get_first_char(i, figlet_left))) do | |
i += 1 | |
abort("Partial result:#{res}") if i > 9 | |
end | |
figlet_left = remove_first_char(i + 1, figlet_left) | |
res << x | |
end | |
puts res | |
} |
This file contains hidden or 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 'epitools' | |
require 'digest/sha1' | |
def hash_fig(arr) | |
Digest::SHA1.hexdigest(arr.join("\n")) | |
end | |
def columnize(arr) | |
arr.map(&:chars).transpose | |
end | |
ALPHABET = [*'A'..'Z'] | |
FIGS = `figlet -f big -w 11 "#{ALPHABET.join("\n")}"`.split("\n").each_slice(8).map { |fig| columnize(fig[0..5]) } | |
LUT = Hash[ FIGS.map {|fig| hash_fig(fig) }.zip(ALPHABET) ] | |
figlet = columnize(File.readlines('figlet.input')) | |
time { | |
result = "" | |
pos = 5 | |
until figlet.empty? or pos > figlet.size | |
hash = hash_fig(figlet[0...pos]) | |
if x = LUT[hash] | |
result << x | |
figlet = figlet[pos..-1] # drop the letter | |
pos = 5 | |
else | |
pos += 1 | |
end | |
end | |
puts result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:D