Skip to content

Instantly share code, notes, and snippets.

@pahnin
Created January 1, 2013 20:01
Show Gist options
  • Save pahnin/4429625 to your computer and use it in GitHub Desktop.
Save pahnin/4429625 to your computer and use it in GitHub Desktop.
One can use this code to generate random questions which is returned in a text format and shall be converted to image form and validate the answer response with the answer. Test run this code at http://www.programr.com/Ruby/IntelligentCaptcha
class Captcha
def initialize
@numbers=[1,2,3,4,5,6,7,8,9]
@numbers_alpha={
1 => "one",
2 => "two",
3 => "three",
4 => "four",
5 => "five",
6 => "six",
7 => "seven",
8 => "eight",
9 => "nine"
}
@ops={
"+" => "plus",
"-" => "minus",
"*" => "multiplies",
"/" => "divided by"
}
end
def array
digit1=@numbers[rand(9)]
digit2=@numbers[rand(9)]
op=@ops.keys[rand(4)]
val = eval "#{digit1}#{op}#{digit2}"
captcha_text = "#{@numbers_alpha[digit1]} #{@ops[op]} #{@numbers_alpha[digit2]}" #
return val,captcha_text
end
end
a=Captcha.new.array
puts a.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment