Created
October 5, 2021 16:43
-
-
Save kirill578/bb69109f7ebe3cf2a5674e7d72b579c8 to your computer and use it in GitHub Desktop.
double lohn barcode in python
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
# output: | |
# 100000000 -> A10000000086 | |
# 100000001 -> A10000000164 | |
# 100000002 -> A10000000242 | |
# 100000003 -> A10000000320 | |
# 100000004 -> A10000000407 | |
# 100000005 -> A10000000575 | |
def luhn_checksum(number): | |
total=0 | |
digits = list(map(int,str(number))) | |
reversedDigits = digits[::-1] | |
total = 0 | |
for position, digit in enumerate(reversedDigits): | |
if (position + 1) % 2 == 1: | |
digit *= 2 | |
if digit > 9: digit -= 9 | |
total += digit | |
total = total * 9 | |
return str(total % 10) | |
for x in range(6): | |
value = 100000000 + x | |
newValue = "A" + str(value) + str(luhn_checksum(value)) + str(luhn_checksum(value + 1)) | |
print(" " + str(value) + " -> " + newValue) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment