|
Algorithm::LUHN - Calculate the Modulus 10 Double Add Double checksum |
Algorithm::LUHN - Calculate the Modulus 10 Double Add Double checksum
use Algorithm::LUHN qw/check_digit is_valid/;
$c = check_digit("43881234567");
print "It works\n" if is_valid("43881234567$c");
$c = check_digit("A2C4E6G8"); # this will cause an error
print "Valid LUHN characters are:\n";
my %vc = Algorithm::LUHN::valid_chars();
for (sort keys %vc) {
print "$_ => $vc{$_}\n";
}
Algorithm::LUHN::valid_chars(map {$_ => ord($_)-ord('A')+10} A..Z);
$c = check_digit("A2C4E6G8");
print "It worked again\n" if is_valid("A2C4E6G8$c");
This module calculates the Modulus 10 Double Add Double checksum, also known as the LUHN Formula. This algorithm is used to verify credit card numbers and Standard & Poor's security identifiers such as CUSIP's and CSIN's.
You can find plenty of information about the algorithm by searching the web for ``modulus 10 double add double''.
This function is equivalent to
substr $N,length($N)-1 eq check_digit(substr $N,0,length($N)-1)
LIST is a mapping of c<character> => c<value>. For example, Standard & Poor's maps A..Z to 10..35 so the LIST to add these valid characters would be (A, 10, B, 11, C, 12, ...)
Please note that this adds or re-maps characters, so any characters already considered valid but not in LIST will remain valid.
If you do not provide LIST, this function returns the current valid character map.
This module was written by Tim Ayers (http://search.cpan.org/search?author=TAYERS).
Copyright (c) 2001 Tim Ayers. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
Algorithm::LUHN - Calculate the Modulus 10 Double Add Double checksum |