Skip to content

Instantly share code, notes, and snippets.

@pahnin
Created June 18, 2012 15:18
Show Gist options
  • Save pahnin/2948877 to your computer and use it in GitHub Desktop.
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"]
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