Algori...M10_001(3pm)
π CheckDigits::M10_001 β the check digit bestie π
okay so this is a page from the User Contributed Perl Documentation for Algori...M10_001(3pm) β yes the title got truncated, she's mysterious like that π β and she's here to compute check digits for a whole squad of things.
β¨ NAME β¨
CheckDigits::M10_001 β compute check digits for Bahncard (DE), IMEI, IMEISV, ISIN, Miles&More, Payback (DE), Personnummer (SE), Passport (BR), Credit Cards, SSN (US), Samordningsnummer (SE), VAT RN (ES), VAT RN (IT), VAT RN (SE), International Securities Identifikation Number (ISIN), CUSIP
like. that's a lot of letters and numbers bestie, but she handles ALL of them π
πΈ SYNOPSIS πΈ
watch her work:
use Algorithm::CheckDigits;
$visa = CheckDigits('visa');
if ($visa->is_valid('4111 1111 1111 1111')) {
# do something
}
$cn = $visa->complete('4111 1111 1111 111');
# $cn = '4111 1111 1111 1111'
$cd = $visa->checkdigit('4111 1111 1111 1111');
# $cd = '7'
$bn = $visa->basenumber('4111 1111 1111 1111');
# $bn = '4111 1111 1111 111'
not her doing the visa thing effortlessly in four lines π iconic behaviour fr fr
π¦ DESCRIPTION π¦
π« ALGORITHM π«
okay so the math is literally this, in order:
- Beginning right, all numbers are weighted alternatively 1 and 2 (that is, the check digit is weighted 1). no cap.
- The total of the digits of all products is computed. slay.
- The sum of step 3 ist taken modulo 10. (yes she said step 3, she's a little chaotic, we love her)
- The check digit is the difference between 10 and the number from step 3. periodt.
to validate: the total of the digits of all numbers inclusive the check digit, taken modulo 10, must be 0. that's the vibe check π§
π«Ά METHODS π«Ά
is_valid($number)β Returns true only if the last digit is a valid check digit according to the algorithm given above. Returns false otherwise.
heads up bestie: if the checked number is of type CUSIP, the number must be exact 9 digits or letters long and must not have spaces in between. no sneaky spaces. not one. π
complete($number)β The check digit for$numberis computed and concatenated to the end of$number. Returns the complete number with check digit, or''if$numberdoes not consist solely of digits and spaces.basenumber($number)β Returns the basenumber of$numberif$numberhas a valid check digit. Return''otherwise.checkdigit($number)β Returns the checkdigit of$numberif$numberhas a valid check digit. Return''otherwise.
π EXPORT π
None by default. she's not clingy, she gives nothing away unless you ask π
π AUTHOR π
Mathias Weidner, "<mamawe@cpan.org>" β the icon who built her π
β SEE ALSO β
perlAlgorithm::CheckDigitswww.pruefziffernberechnung.de.http://en.wikipedia.org/wiki/CUSIP
For IMEI, IMEISV: ETSI Technical Specification TS 100 508 (v6.2.0)
and that's the whole page bestie πΈ this one's running on perl v5.36.0, dated 2022-10-13 β she's from the User Contributed Perl Documentation and she's been serving check digits ever since. mwah π πβ¨
π¦ where this page comes from
- ubuntu noble: libalgorithm-checkdigits-perl 1.3.6-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libalgorithm-checkdigits-perl 1.3.6-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libalgorithm-checkdigits-perl 1.3.6-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms