Created
March 4, 2024 08:37
-
-
Save Veticus/e7b9c9e72186fcac1c1d740423f6ef0c to your computer and use it in GitHub Desktop.
Modulus 11 check, to validate CPR numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note that not all CPR numbers can be validated this way | |
# More info: https://cpr.dk/cpr-systemet/personnumre-uden-kontrolciffer-modulus-11-kontrol | |
def mod11check(cpr_to_check) -> bool: | |
sum2mod = 0 | |
cpr_arr = [int(x) for x in str(cpr_to_check)] | |
for i in range(0, len(cpr_arr)): | |
sum2mod += cpr_arr[i] * [4, 3, 2, 7, 6, 5, 4, 3, 2, 1][i] | |
if sum2mod % 11 == 0: | |
return True | |
else: | |
return False | |
cpr = 2212603611 | |
print(f"Modcheck for CPR number {cpr}: {mod11check(cpr)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment