• 🌙 Community Spirit

    Ramadan Mubarak! To honor this month, Crax has paused NSFW categories. Wishing you peace and growth!

Source Code Advanced Credit Card Validator with Random Generation (1 Viewer)

Currently reading:
 Source Code Advanced Credit Card Validator with Random Generation (1 Viewer)

Recently searched:

1ultrapower

Member
LV
2
Joined
Dec 28, 2023
Threads
10
Likes
7
Awards
6
Credits
5,186©
Cash
0$
import random
import string

def luhn_algorithm(card_number):
card_number = [int(digit) for digit in card_number[::-1]]
total = 0

for i in range(len(card_number)):
if i % 2 == 1:
card_number *= 2
if card_number > 9:
card_number -= 9

total += card_number

return total % 10 == 0

def get_card_type(card_number):
# Determine the card type based on prefixes
card_types = {
"Visa": ["4"],
"MasterCard": ["51", "52", "53", "54", "55"],
"American Express": ["34", "37"],
"Discover": ["6011"]
# Add other card types if needed
}

for card_type, prefixes in card_types.items():
for prefix in prefixes:
if card_number.startswith(prefix):
return card_type

return "Unknown"

def generate_random_credit_card():
# Generate a random credit card number with the appropriate prefix
card_type = random.choice(list(card_types.keys()))
prefix = random.choice(card_types[card_type])
suffix = ''.join(random.choice(string.digits) for _ in range(9))
card_number = f"{prefix}{suffix}"

# Apply the Luhn algorithm to generate the last digit
check_digit = calculate_check_digit(card_number)
card_number += str(check_digit)

return card_number

def calculate_check_digit(card_number):
# Calculate the last digit using the Luhn algorithm
card_number = [int(digit) for digit in card_number[::-1]]
total = 0

for i in range(len(card_number)):
if i % 2 == 0:
card_number *= 2
if card_number > 9:
card_number -= 9

total += card_number

return (10 - (total % 10)) % 10

def validate_credit_card(card_number):
# Remove spaces and dashes from the card number
card_number = card_number.replace(" ", "").replace("-", "")

if not card_number.isdigit() or len(card_number) != 16:
return False # The card number must have exactly 16 digits

return luhn_algorithm(card_number)

# Example usage
test_credit_card = generate_random_credit_card()
print(f"Generated Credit Card Number: {test_credit_card}")
print(f"Card Type: {get_card_type(test_credit_card)}")

if validate_credit_card(test_credit_card):
print("The credit card number is valid.")
else:
print("The credit card number is not valid.")
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips
Recently searched:

Similar threads

Users who are viewing this thread

Top Bottom