The Credit Card Fraudster
Description
This CTF starts with a small story and very easy but the story a bit funny.
According to the requirements of the topic we need “generate” a credit card number. The number on this card must be divisible by 123457 and pass Luhn check.
Card Details ?
Card Number: 543210**1234
Tips: The vast majority of the card numbers total 16.
Solution
First of the all you need to write a function that can do luhn check.
You can try using your card number to verify if the algorithm is correct. It should return True.
After that try to find out all the number are divisible by 123457 before the luhn check.
Try to generate all the permutations or “permutations_with_replacement”
SPOILER WARNING
# Card Number: 543210******1234
# Luhn Algorithm
# card number multiple of 123457
# card total number should be 16
# Use product because duplicate numbers are allowed
from itertools import product
def luhn_algorith_check(number: str) -> bool:
number_arr = [int(dig) for dig in number]
number_arr = number_arr[::-1]
# As algorithm requires first digit position start with 1
for i in range(len(number_arr)):
if i % 2 != 0:
number_arr[i] *= 2
if number_arr[i] > 9:
number_arr[i] -= 9
total = sum(number_arr)
return total % 10 == 0
start_with = "543210"
end_with = "1234"
first_step_check = []
digits = "0123456789"
for i in product(digits, digits, digits, digits, digits, digits):
card_number = start_with + "".join(i) + end_with
if int(card_number) % 123457 == 0:
first_step_check.append(card_number)
# print(first_step_check) # for checking any number pass first check
for i in first_step_check:
if luhn_algorith_check(i):
print(i)