Algori...M11_012(3pm)
π 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 π
- 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,
);
- All those weighted digits get added together. that's the sum, bestie. β
- Then you take that sum from step 2 and hit it with the modulo
11. βοΈ - And the checksum? It's
11minus 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
- 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