Algori...M11_012(3pm)

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

πŸ’– NAME πŸ’–

CheckDigits::M11_012 β€” no cap, this module computes the check digits for the Bundeswehrpersonenkennnummer (that's German for "Bundeswehr personal identification number", bestie, and yes it's a whole vibe). πŸ‡©πŸ‡ͺ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

okay so literally the whole thing in action:

use Algorithm::CheckDigits;

$bwpk = CheckDigits('bwpk_de');

if ($bwpk->is_valid('151058-D-20711')) {
      # do something
}

$cn = $bwpk->complete('151058-D-2071');
# $cn = '151058-D-20711'

$cd = $bwpk->checkdigit('151058-D-20711');
# $cd = '1'

$bn = $bwpk->basenumber('151058-D-20711');
# $bn = '151058-D-2071';

like… it just works. πŸ’…


🌸 DESCRIPTION 🌸

✨ ALGORITHM ✨

grab a snack, we're doing math πŸ“

  1. Starting from the left, every single digit gets weighted, and the weights go like this: 2,3,4,5,6,7,1,6,7,2,3. And the letters?? They get swapped out for numbers using this little lookup table, iykyk:
my %table_to = (
      A => 12, B => 14, C => 16, D => 18, E => 20,
      F => 22, G => 24, H => 26, I => 28, J => 6,
      K => 8, L => 10, M => 12, N => 14, O => 16,
      P => 18, Q => 20, R => 22, S => 4, T => 6,
      U => 8, V => 10, W => 12, X => 14, Y => 16,
      Z => 18,
);
  1. All those weighted digits get added together. that's the sum, bestie. βž•
  2. Then you take that sum from step 2 and hit it with the modulo 11. βœ‚οΈ
  3. And the checksum? It's 11 minus whatever you got in step 3. πŸŽ€

If that difference comes out to 10, the checkdigit is 0.

If that difference comes out to 11, the checkdigit is 1.

🫢 METHODS 🫢

is_valid($number)

Returns true only if $number consists solely of numbers, letters and hyphens, and the rightmost digit is a valid check digit per the algorithm we just explained above. πŸ‘‘

Returns false otherwise. (yes, there's a comma at the end of that sentence in the source. iconic.)

complete($number)

It computes the check digit for $number and appends it right onto the end of $number. ✨

Returns the complete number with the check digit β€” or '' if $number does not consist solely of digits, hyphens and spaces. (not me noticing it says digits/hyphens/spaces here while is_valid said numbers/letters/hyphens… that's just how it is, bestie, I don't make the rules πŸ’€)

basenumber($number)

Returns the basenumber of $number if $number has a valid check digit. πŸ¦‹

Return '' otherwise.

checkdigit($number)

Returns the check digits of $number if $number has valid check digits. πŸŽ€

Return '' otherwise.

πŸ’œ EXPORT πŸ’œ

None by default. like… nothing. zero. she gives you nothing unless you ask. πŸ™ˆ


πŸ‘‘ AUTHOR πŸ‘‘

Mathias Weidner, "<mamawe@cpan.org>" β€” thank you for your service, king πŸ«‘πŸ’–


🌈 SEE ALSO 🌈

perl, CheckDigits, www.pruefziffernberechnung.de,


and that's the whole page, bestie!! this lil beauty is perl v5.36.0, dated 2022-10-13, from the Algori...M11_012(3pm) page in the User Contributed Perl Documentation β€” main character energy from start to finish, periodt. β­πŸ’…πŸŒ·

πŸ“¦ where this page comes from