Created
June 18, 2012 15:18
-
-
Save pahnin/2948877 to your computer and use it in GitHub Desktop.
ruby programm to return array of text and its value, can be used as alterantives to captcha. Example: [4, "four divided by one"] , [0, "eight minus eight"] , [6, "two plus four"]
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
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)] | |
[email protected][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