Algorithm-LUHN_XS
view release on metacpan or search on metacpan
- Remove XSMULTI and move XS file to base directory
1.03 2018-12-03 KSCHWAB
- Add min requirement of 0.16 for XSLoader
1.02 2018-12-03 KSCHWAB
- Substantial performance improvement
- Add ExtUtils::MakeMaker 7.12 to CONFIGURE_REQUIRES
1.01 2018-12-02 KSCHWAB
- Typo in Credits
1.00 2018-12-02 KSCHWAB
- First release to CPAN
"check_digit_rff: 1 secs ( 1.29 usr 0.00 sys) 77.52/s"
So, it's 35x to 53x faster than the original pure Perl module, depending
on how much compatibility with the original module you need.
The rest of the documentation is mostly a copy of the original docs,
with some additions for functions that are new.
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".
FUNCTION
is_valid CHECKSUMMED_NUM
This function takes a credit-card number and returns true if the
number passes the LUHN check.
Ie it returns true if the final character of CHECKSUMMED_NUM is the
correct checksum for the rest of the number and false if not.
Obviously the final character does not factor into the checksum
calculation. False will also be returned if NUM contains in an
invalid character as defined by valid_chars(). If NUM is not valid,
$Algorithm::LUHN_XS::ERROR will contain the reason.
This function is equivalent to
$Algorithm::LUHN_XS::ERROR to contain the reason why. It's about 20%
faster than check_digit() because the XS code in this case only has
to return integers.
check_digit_rff NUM
This function returns the checksum of the given number.
It's about 50% faster than check_digit() because it doesn't support
the valid_chars() function, and only produces a valid output for
numeric input. If you pass it input with alpha characters, it will
return -1. Works great for Credit Cards, but not for things like
CUSIP identifiers <https://en.wikipedia.org/wiki/CUSIP>.
valid_chars LIST
By default this module only recognizes 0..9 as valid characters, but
sometimes you want to consider other characters as valid, e.g.
Standard & Poor's identifers may contain 0..9, A..Z, @, #, *. This
function allows you to add additional characters to the accepted
list.
LIST is a mapping of "character" => "value". For example, Standard &
Also, be careful with passing long numbers around. Perl will, depending
on the context, convert things like 12345678912345 to
1.2345678912345e+1. Try to keep things in "string context".
SEE ALSO
Algorithm::LUHN is the original pure perl module this is based on.
Algorithm::CheckDigits provides a front-end to a large collection of
modules for working with check digits.
Business::CreditCard provides three functions for checking credit card
numbers. Business::CreditCard::Object provides an OO interface to those
functions.
Business::CardInfo provides a class for holding credit card details, and
has a type constraint on the card number, to ensure it passes the LUHN
check.
Business::CCCheck provides a number of functions for checking credit
card numbers.
Regexp::Common supports combined LUHN and issuer checking against a card
number.
Algorithm::Damm implements a different kind of check digit algorithm,
the Damm algorithm <https://en.wikipedia.org/wiki/Damm_algorithm> (Damm,
not Damn).
Math::CheckDigits implements yet another approach to check digits.
`check_digit_rff: 1 secs ( 1.29 usr 0.00 sys) 77.52/s`
So, it's 35x to 53x faster than the original pure Perl module, depending on
how much compatibility with the original module you need.
The rest of the documentation is mostly a copy of the original docs, with some
additions for functions that are new.
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".
# FUNCTION
- is\_valid CHECKSUMMED\_NUM
This function takes a credit-card number and returns true if
the number passes the LUHN check.
Ie it returns true if the final character of CHECKSUMMED\_NUM is the
correct checksum for the rest of the number and false if not. Obviously the
final character does not factor into the checksum calculation. False will also
be returned if NUM contains in an invalid character as defined by
valid\_chars(). If NUM is not valid, $Algorithm::LUHN\_XS::ERROR will contain the
reason.
This function is equivalent to
This function returns the checksum of the given number. If it cannot calculate
the check digit it will return -1 and set $Algorithm::LUHN\_XS::ERROR to
contain the reason why. It's about 20% faster than check\_digit() because the XS
code in this case only has to return integers.
- check\_digit\_rff NUM
This function returns the checksum of the given number.
It's about 50% faster than check\_digit() because it doesn't support the valid\_chars() function, and only produces a valid output for numeric input. If you pass
it input with alpha characters, it will return -1. Works great for Credit
Cards, but not for things like [CUSIP identifiers](https://en.wikipedia.org/wiki/CUSIP).
- valid\_chars LIST
By default this module only recognizes 0..9 as valid characters, but sometimes
you want to consider other characters as valid, e.g. Standard & Poor's
identifers may contain 0..9, A..Z, @, #, \*. This function allows you to add
additional characters to the accepted list.
LIST is a mapping of `character` => `value`.
on the context, convert things like 12345678912345 to 1.2345678912345e+1.
Try to keep things in "string context".
# SEE ALSO
[Algorithm::LUHN](https://metacpan.org/pod/Algorithm::LUHN) is the original pure perl module this is based on.
[Algorithm::CheckDigits](https://metacpan.org/pod/Algorithm::CheckDigits) provides a front-end to a large collection
of modules for working with check digits.
[Business::CreditCard](https://metacpan.org/pod/Business::CreditCard) provides three functions for checking credit
card numbers. [Business::CreditCard::Object](https://metacpan.org/pod/Business::CreditCard::Object) provides an OO interface
to those functions.
[Business::CardInfo](https://metacpan.org/pod/Business::CardInfo) provides a class for holding credit card details,
and has a type constraint on the card number, to ensure it passes the
LUHN check.
[Business::CCCheck](https://metacpan.org/pod/Business::CCCheck) provides a number of functions for checking
credit card numbers.
[Regexp::Common](https://metacpan.org/pod/Regexp::Common) supports combined LUHN and issuer checking
against a card number.
[Algorithm::Damm](https://metacpan.org/pod/Algorithm::Damm) implements a different kind of check digit algorithm,
the [Damm algorithm](https://en.wikipedia.org/wiki/Damm_algorithm)
(Damm, not Damn).
[Math::CheckDigits](https://metacpan.org/pod/Math::CheckDigits) implements yet another approach to check digits.
lib/Algorithm/LUHN_XS.pm view on Meta::CPAN
C<check_digit_rff: 1 secs ( 1.29 usr 0.00 sys) 77.52/s>
So, it's 35x to 53x faster than the original pure Perl module, depending on
how much compatibility with the original module you need.
The rest of the documentation is mostly a copy of the original docs, with some
additions for functions that are new.
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".
=head1 FUNCTION
=over 4
=cut
=item is_valid CHECKSUMMED_NUM
This function takes a credit-card number and returns true if
the number passes the LUHN check.
Ie it returns true if the final character of CHECKSUMMED_NUM is the
correct checksum for the rest of the number and false if not. Obviously the
final character does not factor into the checksum calculation. False will also
be returned if NUM contains in an invalid character as defined by
valid_chars(). If NUM is not valid, $Algorithm::LUHN_XS::ERROR will contain the
reason.
This function is equivalent to
lib/Algorithm/LUHN_XS.pm view on Meta::CPAN
contain the reason why. It's about 20% faster than check_digit() because the XS
code in this case only has to return integers.
=cut
=item check_digit_rff NUM
This function returns the checksum of the given number.
It's about 50% faster than check_digit() because it doesn't support the valid_chars() function, and only produces a valid output for numeric input. If you pass
it input with alpha characters, it will return -1. Works great for Credit
Cards, but not for things like L<CUSIP identifiers|https://en.wikipedia.org/wiki/CUSIP>.
=cut
# check_digit, check_digit_fast, and check_digit_rff are XS defined functions
=item valid_chars LIST
By default this module only recognizes 0..9 as valid characters, but sometimes
you want to consider other characters as valid, e.g. Standard & Poor's
lib/Algorithm/LUHN_XS.pm view on Meta::CPAN
Try to keep things in "string context".
=head1 SEE ALSO
L<Algorithm::LUHN> is the original pure perl module this is based on.
L<Algorithm::CheckDigits> provides a front-end to a large collection
of modules for working with check digits.
L<Business::CreditCard> provides three functions for checking credit
card numbers. L<Business::CreditCard::Object> provides an OO interface
to those functions.
L<Business::CardInfo> provides a class for holding credit card details,
and has a type constraint on the card number, to ensure it passes the
LUHN check.
L<Business::CCCheck> provides a number of functions for checking
credit card numbers.
L<Regexp::Common> supports combined LUHN and issuer checking
against a card number.
L<Algorithm::Damm> implements a different kind of check digit algorithm,
the L<Damm algorithm|https://en.wikipedia.org/wiki/Damm_algorithm>
(Damm, not Damn).
L<Math::CheckDigits> implements yet another approach to check digits.
( run in 0.385 second using v1.01-cache-2.11-cpan-de7293f3b23 )