Algori...M10_001(3pm)

πŸ“¦
version 1.3.6 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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:

  1. Beginning right, all numbers are weighted alternatively 1 and 2 (that is, the check digit is weighted 1). no cap.
  2. The total of the digits of all products is computed. slay.
  3. The sum of step 3 ist taken modulo 10. (yes she said step 3, she's a little chaotic, we love her)
  4. 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 $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. she's not clingy, she gives nothing away unless you ask πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

Mathias Weidner, "<mamawe@cpan.org>" β€” the icon who built her πŸŽ€


⭐ SEE ALSO ⭐

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