Algori...MXX_001(3pm)

๐Ÿ“ฆ
version 1.3.6 ยท 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– CheckDigits::MXX_001 โ€” it's giving check digits ๐Ÿ’–

okay so bestie, welcome to Algori...MXX_001(3pm) from the User Contributed Perl Documentation โœจ this one lives in the CheckDigits family (the Algorithm::CheckDigits girlies ๐ŸŽ€) and she does exactly two jobs: she computes check digits for the german Personalausweis (pa_de) ๐Ÿ‘‘ and for ABA routing numbers (aba_rn) ๐Ÿฆ. lowkey iconic. let's get into it ๐Ÿ’…


โœจ NAME โœจ

CheckDigits::MXX_001 โ€” compute check digits for german Personalausweis (pa_de) or ABA routing numbers (aba_rn) ๐Ÿฆ‹


๐ŸŒธ SYNOPSIS ๐ŸŒธ

no cap, here's the whole vibe verbatim:

use Algorithm::CheckDigits;

$pa = CheckDigits('pa_de');

if ($pa->is_valid('2406055684D<<6810203<0705109<6')) {
      # do something
}

if ($pa->is_valid('2406055684') {
      # do_something
}

$cn = $pa->complete('240605568_D<<681020_<070510_<_');
# $cn = '2406055684D<<6810203<0705109<6'

$cd = $pa->checkdigit('2406055684D<<6810203<0705109<6');
# $cd = '6'

$bn = $pa->basenumber('2406055684D<<6810203<0705109<6');
# $bn = '240605568_D<<681020_<070510_<_'

$aba = CheckDigits('aba_rn');
if ($aba->is_valid('789456124')) {
     # do something
}

(not me noticing that second is_valid line is missing a closing paren ๐Ÿ˜ญ โ€” that's exactly how she's printed in the original, so I'm keeping her that way, periodt. copy-paste responsibly bestie ๐Ÿ’€)


๐ŸŒˆ DESCRIPTION ๐ŸŒˆ

๐Ÿ”ข ALGORITHM ๐Ÿ”ข

okay so here's the whole math situation, step by step, main character energy only:

  1. Beginning left all digits are weighted with 7,3,1,7,3,1,... for pa_de or 3,7,1,3,7,1,3,7,1 for aba_rn. ๐ŸŽ€
  2. The sum of those products is computed. that's the moment, fr fr. โœจ
  3. For pa_de the checksum is the last digit of the sum from step 2 (modulo 10). ๐Ÿ”ฅ

For aba_rn the checksum is the difference of the sum from step 2 to the next multiple of 10. ๐Ÿงฎ

  1. For the german Personalausweis step 1 to 3 is performed for every part of the number and for all 3 parts including the particular checkdigit to compute the total checksum. ๐Ÿ’…

If the number solely consists of digits, the checksum is just computed once according to algorithm given above. ๐Ÿซถ


๐Ÿ› ๏ธ METHODS ๐Ÿ› ๏ธ

  • is_valid($number) โ€” Returns true only if $number consists solely of numbers and the last digit is a valid check digit according to the algorithm given above. Returns false otherwise. (so basically: valid = slay, invalid = not slay ๐ŸŒธ)
  • complete($number) โ€” The check digit for $number is computed and concatenated to the end of $number. Returns the complete number with check digit or '' if $number does not consist solely of digits and spaces. โœจ
  • basenumber($number) โ€” Returns the basenumber of $number if $number has a valid check digit. Return '' otherwise. ๐Ÿ‘‘
  • checkdigit($number) โ€” Returns the checkdigit of $number if $number has a valid check digit. Return '' otherwise. ๐Ÿ’œ

๐Ÿ“ฆ EXPORT ๐Ÿ“ฆ

None by default. that's it, that's the export section, she's shy ๐Ÿ™ˆ


๐Ÿซถ AUTHOR ๐Ÿซถ

Mathias Weidner, "<mamawe@cpan.org>" ๐Ÿ’– living legend!!


๐Ÿ’ THANKS ๐Ÿ’

Aaron W. West pointed me to a fault in the computing of the check digit. Jim Hickstein made me aware of the ABA routing numbers. we love a collaborative queen ๐ŸŒˆโœจ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

perl, CheckDigits, www.pruefziffernberechnung.de, http://answers.google.com/answers/threadview/id/43619.html, http://www.brainjar.com/js/validation/ ๐Ÿฆ‹


and that's the whole page bestie!! ๐Ÿ’… quick lil sign-off so you know where this lore came from: this is from perl v5.36.0, dated 2022-10-13, and it's the Algori...MXX_001(3pm) page โ€” go forth and validate those Personalausweise and ABA routing numbers, you absolute icon ๐ŸŽ€๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from