#!@ruby_exe@ require 'cgi' require ENV['DOCUMENT_ROOT'] + '/test/ruby/LUHN' if ENV['QUERY_STRING'].nil? then answer = '' numebr = '' else query = CGI.parse(ENV['QUERY_STRING']) number = query['number'].to_s case query['action'].to_s when 'Validate' is_valid = LUHN.valid?(number) answer = number when 'Generate' digit = LUHN.generate(number) answer = "#{number}" + digit.to_s is_valid = ! digit.nil? end end puts <<"EOT" HTTP/1.0 200 OK Content-Type: text/html Hibachi - Playing with LUHN checksums in Ruby

Playing with LUHN checksums in Ruby
"mod 10 Double-Add-Double"

Enter an alpha-numeric string like a credit card number or International Securities Identification Number (ISO 6166). Click validate to test if the entered string is correct. Click generate to append the check digit to the string.


#{ is_valid ? "Is valid." : "Is NOT valid." }

     

Return to HIBACHI
EOT exit(0)