Skip to content

Instantly share code, notes, and snippets.

@AtufaShireen
Created July 28, 2020 17:20
Show Gist options
  • Save AtufaShireen/6252368aa4016e99b7101f489dcb5b92 to your computer and use it in GitHub Desktop.
Save AtufaShireen/6252368aa4016e99b7101f489dcb5b92 to your computer and use it in GitHub Desktop.
import random
first_6=400000 # IIN For Banking Industry(6 digits)
def luhn():
global first_6
card_no = [int(i) for i in str(first_6)] # To find the checksum digit on
card_num = [int(i) for i in str(first_6)] # Actual account number
seventh_15 = random.sample(range(9), 9) # Acc no (9 digits)
for i in seventh_15:
card_no.append(i)
card_num.append(i)
for t in range(0, 15, 2): # odd position digits
card_no[t] = card_no[t] * 2
for i in range(len(card_no)):
if card_no[i] > 9: # deduct 9 from numbers greater than 9
card_no[i] -= 9
s = sum(card_no)
mod = s % 10
check_sum = 0 if mod == 0 else (10 - mod)
card_num.append(check_sum)
card_num = [str(i) for i in card_num]
return ''.join(card_num)
print(luhn())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment