Skip to content

Instantly share code, notes, and snippets.

@kirill578
Created October 5, 2021 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirill578/bb69109f7ebe3cf2a5674e7d72b579c8 to your computer and use it in GitHub Desktop.
Save kirill578/bb69109f7ebe3cf2a5674e7d72b579c8 to your computer and use it in GitHub Desktop.
double lohn barcode in python
# 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