| Server IP : 216.92.14.13 / Your IP : 216.73.216.171 Web Server : Apache System : Linux vps4089.pairvps.com 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 User : rmlac2fmr ( 1040637) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/man/man3/ |
Upload File : |
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
. if \nF \{
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Algorithm::LUHN 3"
.TH Algorithm::LUHN 3 "2014-06-29" "perl v5.22.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Algorithm::LUHN \- Calculate the Modulus 10 Double Add Double checksum
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Algorithm::LUHN qw/check_digit is_valid/;
\&
\& $c = check_digit("43881234567");
\& print "It works\en" if is_valid("43881234567$c");
\&
\& $c = check_digit("A2C4E6G8"); # this will cause an error
\&
\& print "Valid LUHN characters are:\en";
\& my %vc = Algorithm::LUHN::valid_chars();
\& for (sort keys %vc) {
\& print "$_ => $vc{$_}\en";
\& }
\&
\& Algorithm::LUHN::valid_chars(map {$_ => ord($_)\-ord(\*(AqA\*(Aq)+10} A..Z);
\& $c = check_digit("A2C4E6G8");
\& print "It worked again\en" if is_valid("A2C4E6G8$c");
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This module calculates the Modulus 10 Double Add Double checksum, also known as
the \s-1LUHN\s0 Formula. This algorithm is used to verify credit card numbers and
Standard & Poor's security identifiers such as \s-1CUSIP\s0's and \s-1CSIN\s0's.
.PP
You can find plenty of information about the algorithm by searching the web for
\&\*(L"modulus 10 double add double\*(R".
.SH "FUNCTION"
.IX Header "FUNCTION"
.IP "is_valid \s-1CHECKSUMMED_NUM\s0" 4
.IX Item "is_valid CHECKSUMMED_NUM"
This function takes a credit-card number and returns true if
the number passes the \s-1LUHN\s0 check.
.Sp
Ie it returns true if the final character of \s-1CHECKSUMMED_NUM\s0 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 \s-1NUM\s0 contains in an invalid character as defined by
\&\fIvalid_chars()\fR. If \s-1NUM\s0 is not valid, \f(CW$Algorithm::LUHN::ERROR\fR will contain the
reason.
.Sp
This function is equivalent to
.Sp
.Vb 1
\& substr $N,length($N)\-1 eq check_digit(substr $N,0,length($N)\-1)
.Ve
.Sp
For example, \f(CW\*(C`4242 4242 4242 4242\*(C'\fR is a valid Visa card number,
that is provided for test purposes. The final digit is '2',
which is the right check digit. If you change it to a '3', it's not
a valid card number. Ie:
.Sp
.Vb 2
\& is_valid(\*(Aq4242424242424242\*(Aq); # true
\& is_valid(\*(Aq4242424242424243\*(Aq); # false
.Ve
.IP "check_digit \s-1NUM\s0" 4
.IX Item "check_digit NUM"
This function returns the checksum of the given number. If it cannot calculate
the check_digit it will return undef and set \f(CW$Algorithm::LUHN::ERROR\fR to contain
the reason why.
.IP "valid_chars \s-1LIST\s0" 4
.IX 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
identifers may contain 0..9, A..Z, @, #, *. This function allows you to add
additional characters to the accepted list.
.Sp
\&\s-1LIST\s0 is a mapping of c<character> => c<value>. For example, Standard & Poor's
maps A..Z to 10..35 so the \s-1LIST\s0 to add these valid characters would be (A, 10,
B, 11, C, 12, ...)
.Sp
Please note that this \fIadds\fR or \fIre-maps\fR characters, so any characters
already considered valid but not in \s-1LIST\s0 will remain valid.
.Sp
If you do not provide \s-1LIST,\s0 this function returns the current valid character
map.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Algorithm::CheckDigits provides a front-end to a large collection
of modules for working with check digits.
.PP
Business::CreditCard provides three functions for checking credit
card numbers. Business::CreditCard::Object provides an \s-1OO\s0 interface
to those functions.
.PP
Business::CardInfo provides a class for holding credit card details,
and has a type constraint on the card number, to ensure it passes the
\&\s-1LUHN\s0 check.
.PP
Business::CCCheck provides a number of functions for checking
credit card numbers.
.PP
Regexp::Common supports combined \s-1LUHN\s0 and issuer checking
against a card number.
.PP
I have also written a
review of \s-1LUHN\s0 modules <http://neilb.org/reviews/luhn.html>,
which covers them in more detail than this section.
.SH "REPOSITORY"
.IX Header "REPOSITORY"
<https://github.com/neilbowers/Algorithm\-LUHN>
.SH "AUTHOR"
.IX Header "AUTHOR"
This module was written by
Tim Ayers (http://search.cpan.org/search?author=TAYERS).
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (c) 2001 Tim Ayers. All rights reserved.
.SH "LICENSE"
.IX Header "LICENSE"
This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.