<stdin> |

My Thoughts, Trials and Adventures

Xcard library

Posted at — Aug 20, 2020 | Last Modified on — May 11, 2023

Introduction

xcard is a library to generate and validate credit/debit cards. it’s divided into two classes:

xcardMT class consists of multithreaded functions which are useful when processing millions of cards.

Luhn checksum

The Luhn algorithm or Luhn formula, also known as the “modulus 10” or “mod 10” algorithm, named after its creator, IBM scientist Hans Peter Luhn, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers in the United States, Canadian Social Insurance Numbers, Israeli ID Numbers, South African ID Numbers, Greek Social Security Numbers (ΑΜΚΑ), and survey codes appearing on McDonald’s, Taco Bell, and Tractor Supply Co. receipts.

From Wikipedia: Luhn algorithm


using xcard library

demo.cpp contains simple code to generate a random credit card with prefix 4(VISA)

#include <iostream>
#include <vector>
#include <threads.h>
#include "../include/xcard.hpp"

int main()
{

    //initialize
    xcard xc("4", false);

    std::cout << "xcard version: " << xc.VERSION << std::endl;

    std::cout << "Generate 10 random valid cards with prefix 4" << std::endl;

    for (int i = 0; i < 10; i++)
    {
        std::cout << xc.generateCard() << std::endl;
    }

    return 0;
}

xcardMT consists of a constructor which takes 3 arguments (prefix, no of threads and debug switch) and two multi-threaded functions:

public:
    xcardMT(std::string prefix, int threads, int debug);
    std::vector<bool> validateFromFile(std::ifstream &fp);
    std::vector<std::string> LinearSearch();

Conclusion

xcard is a very simple C++ library to validate and generate credit cards, multi-threaded functions are useful to speed up processing on supported CPU(s).