mirror of https://github.com/me50/kukemuna.git
This commit is contained in:
commit
2563fd8906
|
|
@ -0,0 +1,59 @@
|
|||
import re
|
||||
import sys
|
||||
|
||||
while True:
|
||||
try:
|
||||
card = input("Number: ").strip() # Remove leading and trailing whitespaces
|
||||
if card.isdigit():
|
||||
break
|
||||
except:
|
||||
ValueError
|
||||
|
||||
|
||||
if not (len(card) == 13 or len(card) == 15 or len(card) == 16):
|
||||
print("INVALID")
|
||||
quit()
|
||||
|
||||
|
||||
cardNumber = int(card)
|
||||
numLength = len(card)
|
||||
id = int(card[0:4].splitlines()[0])
|
||||
|
||||
|
||||
sum = multiply = 0
|
||||
|
||||
# Validate cardNumber with Luhn's Algorithm
|
||||
while (cardNumber > 0):
|
||||
if (multiply):
|
||||
if (cardNumber % 10 * 2 > 9):
|
||||
n = cardNumber % 10 * 2
|
||||
while (n > 0):
|
||||
sum += int(n % 10)
|
||||
n = int(n / 10)
|
||||
else:
|
||||
sum += cardNumber % 10 * 2
|
||||
cardNumber = int(cardNumber / 10)
|
||||
multiply = 0
|
||||
else:
|
||||
sum += cardNumber % 10
|
||||
cardNumber = int(cardNumber / 10)
|
||||
multiply = 1
|
||||
if (sum % 10 != 0):
|
||||
print("INVALID")
|
||||
quit()
|
||||
|
||||
|
||||
if ((int(id / 100) == 34 or int(id / 100) == 37) and numLength == 15):
|
||||
print("AMEX")
|
||||
quit()
|
||||
|
||||
if ((int(id / 1000) == 4) and (numLength == 13 or numLength == 16)):
|
||||
print("VISA")
|
||||
quit()
|
||||
|
||||
if (((int(id / 100) >= 51 and int(id / 100) <= 55) or (id >= 2221 and id <= 2720)) and numLength == 16):
|
||||
print("MASTERCARD")
|
||||
quit()
|
||||
|
||||
else:
|
||||
print("INVALID")
|
||||
Loading…
Reference in New Issue