Algori...M11_015(3pm)

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

๐Ÿ’– NAME ๐Ÿ’–

CheckDigits::M11_015 โ€” bestie, this is the module that computes check digits for ESR5 (CH), aka the Swiss payment slip thing, and it's lowkey iconic ๐Ÿ’…

It ships as part of Algorithm::CheckDigits, so like, that's the family it lives in ๐Ÿซถ


โœจ SYNOPSIS โœจ

okay so first you gotta summon it:

use Algorithm::CheckDigits;

$ustid = CheckDigits('esr5_ch');

if ($ustid->is_valid('050001000012000 241170032660178 10304')) {
      # do something
}

$cn = $ustid->complete('0001000012000 241170032660178 10304');
# $cn = '050001000012000 241170032660178 10304'

$cd = $ustid->checkdigit('0001000012000 241170032660178 10304');
# $cd = '05'

$bn = $ustid->basenumber('050001000012000 241170032660178 10304');
# $bn = '0001000012000 241170032660178 10304';

see how the 'esr5_ch' handle gets you your very own $ustid object? and then it just... does the math for you? main character energy fr fr ๐Ÿ‘‘


๐ŸŒธ DESCRIPTION ๐ŸŒธ

๐Ÿงฎ ALGORITHM

the math is giving โœจchecksum realnessโœจ and honestly it's not even hard, watch:

  1. starting from the right, every digit gets weighted with the repeating sequence 2, 3, 4, 5, 6, 7 โ€” and yes bestie it repeats, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, ... forever and ever ๐Ÿ’ซ
  2. add all those weighted digits together ๐Ÿง 
  3. take that sum from step 2 and hit it with modulo 11 ๐Ÿ”ฅ
  4. the checkdigit is 11 minus the sum from step 3. BUT โ€” and this is the plot twist โ€” if that difference comes out to 11, then the checkdigit is 00 ๐Ÿ˜ญ periodt.
โš ๏ธ warning bestie: step 4 is not a typo. when the difference is 11, you write 00. don't come for me, that's just what the spec says ๐Ÿ’€

๐Ÿ› ๏ธ METHODS

  • is_valid($number) โ€” gives you back true only if $number is made up solely of numbers (spaces between them are fine, she's flexible like that ๐Ÿ’…) and the first two digits are valid check digits per the algorithm above. anything else? false. no cap. ๐Ÿ’–
  • complete($number) โ€” computes the check digit for $number and inserts it before the number ๐Ÿ‘‘. she hands you back the complete number with its check digit, or '' if $number isn't made up solely of digits and spaces ๐Ÿ™ˆ
  • basenumber($number) โ€” if $number has a valid check digit, you get the basenumber back ๐ŸŽ€. otherwise? ''. that's it. that's the vibe. ๐Ÿ’€
  • checkdigit($number) โ€” if $number has valid check digits, she returns them ๐Ÿฆ‹. otherwise ''. no notes.

๐Ÿ“ฆ EXPORT

None by default. literally nothing gets exported, she's lowkey mysterious like that ๐Ÿงš


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Mathias Weidner, "<mamawe@cpan.org>" โ€” the icon, the legend, the moment ๐ŸŒŸ


๐Ÿ”— SEE ALSO ๐Ÿ”—


and that's the whole page bestie!! this one was documented for perl v5.36.0 and dated 2022-10-13, so if that's not your perl era, just keep it in mind ๐ŸŒˆ slay, go validate some Swiss payment slips, mwah ๐Ÿ’–โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from