Created
August 24, 2018 14:55
-
-
Save stfnndrsn/1b244e35b2d3cf261417e80ca26d4f55 to your computer and use it in GitHub Desktop.
This file contains 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
def _calculate_ocr_checksum(ocr_code): | |
""" | |
Inspired from https://danskebank.dk/PDF/Blanketter/ERHVERV/Indbetalingskort/Fremstilling_af_71-kort.pdf | |
:param ocr_code: string | |
:return: int | |
""" | |
counter = 0 | |
should_multiply = (len(ocr_code) % 2) == 1 | |
for c in ocr_code: | |
v = int(c) * 2 if should_multiply else int(c) | |
counter += sum(map(int, str(v))) # sum of digits | |
should_multiply = not should_multiply | |
return 10 - (counter % 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
be aware that this code will return '10' instead of '0'