|
|
radical hacks
|
|
|
|
|
|
sent in these useful credit card verifier....
#! /usr/local/bin/perl
$GOOD="5000000000000009";
# $CC="$GOOD"; # FOR TESTING
$CC="5123345612319876";
# pre-screen dates and total number of digits based
# on CC type first.
# then...
# if returned value does not equal 0 the number
# failed checksum test
if (&CheckDigit($CC)) {
print "Invalid Credit Card Number\n"
}else{
print "Credit Card Number is Good\n"
}
exit;
###
sub CheckDigit {
my ($card_number) = @_;
my ($sum, $double, $pos, $digit);
$sum = 0;
$double = 0;
foreach $pos (1 .. length($card_number)) {
$digit = substr($card_number,-$pos,1);
if ($double) {
$double = 0;
$digit += $digit;
if ($digit > 9) {
$digit -= 9;
}
} else {
$double = 1;
}
$sum += $digit;
}
#
# If test passes - return=0 (a "false" flag for if stmt)
return($sum % 10);
}
|
|