Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions stdnum/pl/nip.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,10 +45,15 @@ def compact(number: str) -> str:
return number


_weights = (6, 5, 7, 2, 3, 4, 5, 6, 7, -1)


def checksum(number: str) -> int:
"""Calculate the checksum."""
weights = (6, 5, 7, 2, 3, 4, 5, 6, 7, -1)
return sum(w * int(n) for w, n in zip(weights, number)) % 11
total = 0
for w, n in zip(_weights, number):
total += w * (ord(n) - 48)
return total % 11


def validate(number: str) -> str:
Expand Down
10 changes: 7 additions & 3 deletions stdnum/pl/pesel.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -88,12 +88,16 @@ def get_gender(number: str) -> str:
return 'M'


_weights = (1, 3, 7, 9, 1, 3, 7, 9, 1, 3)


def calc_check_digit(number: str) -> str:
"""Calculate the check digit for organisations. The number passed
should not have the check digit included."""
weights = (1, 3, 7, 9, 1, 3, 7, 9, 1, 3)
check = sum(w * int(n) for w, n in zip(weights, number))
return str((10 - check) % 10)
total = 0
for w, n in zip(_weights, number):
total += w * (ord(n) - 48)
return str((10 - total) % 10)


def validate(number: str) -> str:
Expand Down
Loading