Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion stdnum/nl/bsn.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,36 @@
from stdnum.exceptions import *
from stdnum.util import clean, isdigits

char_to_int = {
'A' : 10,
'B' : 11,
'C' : 12,
'D' : 13,
'E' : 14,
'F' : 15,
'G' : 16,
'H' : 17,
'I' : 18,
'J' : 19,
'K' : 20,
'L' : 21,
'M' : 22,
'N' : 23,
'O' : 24,
'P' : 25,
'Q' : 26,
'R' : 27,
'S' : 28,
'T' : 29,
'U' : 30,
'V' : 31,
'W' : 32,
'X' : 33,
'Y' : 34,
'Z' : 35,
'+' : 36,
'*' : 37,
}

def compact(number):
"""Convert the number to the minimal representation. This strips the
Expand All @@ -72,7 +102,12 @@ def validate(number):
if len(number) != 9:
raise InvalidLength()
if checksum(number) != 0:
raise InvalidChecksum()
check_val = '2321'
for x in number:
if x.isdigit(): check_val += x
else: check_val += str(char_to_int[x])
if int(check_val_sole) % 97 != 1:
raise InvalidChecksum()
return number


Expand Down