Created
December 14, 2022 05:52
-
-
Save exinmusic/bd81aeee864187594acdf54510b27903 to your computer and use it in GitHub Desktop.
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
import sys | |
import random | |
from pprint import pprint | |
def get_cc_number(): | |
if len(sys.argv) < 2: | |
usage() | |
sys.exit(1) | |
return sys.argv[1] | |
def validate(n): | |
r = [int(ch) for ch in str(n)][::-1] | |
return (sum(r[0::2]) + sum(sum(divmod(d*2,10)) for d in r[1::2])) % 10 == 0 | |
def create_giftcard(first_octet): | |
# Initialize an empty list to store the valid numbers | |
valid_numbers = [] | |
while True: | |
# Generate a random 8-digit number as the second octet of the number | |
second_octet = random.randint(100000001, 999999998) | |
# Concatenate the first and second octets to form the 16-digit number | |
number = int(str(first_octet) + str(second_octet)) | |
# Use the validate function to check if the number is valid | |
if validate(number): | |
# If the number is valid, append it to the list of valid numbers and print it along with its validation status | |
valid_numbers.append(number) | |
print(number, "Valid") | |
else: | |
# If the number is not valid, print it along with its validation status | |
print(number, "Not valid") | |
# If the list of valid numbers has 10 elements, return the list | |
if len(valid_numbers) == 10000: | |
return set(valid_numbers) | |
if __name__ == "__main__": | |
pprint(create_giftcard(get_cc_number())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment