

How To Generate A Valid Credit Card Number For A Bin (First 6 Digits)
source link: https://blog.jakubholy.net/2014/03/25/how-to-generate-a-valid-credit-card-number-for-a-bin-first-6-digits/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How To Generate A Valid Credit Card Number For A Bin (First 6 Digits)
org.apache.commons.validator.routines.CreditCardValidator
from common-validator 1.4:
// Groovy:
/** Map RegExp from C.C.Validator to the total length of the CC# */
binReToLen = [
(~/^(3[47]\d{0,13})$/) : 13+2, // amex
(~/^30[0-5]\d{0,11}$/) : 11+3, // diners 1
(~/^(3095\d{0,10})$/) : 10+4, // diners 2
(~/^(36\d{0,12})$/) : 12+2, // diners 3
(~/^|3[8-9]\d{0,12}$/) : 12+2, // diners 4
(~/^(5[1-5]\d{0,14})$/) : 14+2, // master
(~/^(4)(\d{0,12}|\d{15})$/) : 12+1 // visa
// Discover cards omitted
]
/** Bin is e.g. 123456 */
def completeCCn(String bin) {
def ccnFill = "1" * 19
int ccnLen = lenForBin(bin)
def ccnWithoutCheck = bin + ccnFill[0..<(ccnLen - 6 - 1)] // - bin, - check digit
def check = computeLuhncheckDigit(ccnWithoutCheck)
return "$ccnWithoutCheck$check"
}
def lenForBin(String bin) {
def match = binReToLen.find { it.key.matcher(bin).matches() }
if (match == null) {
throw new RuntimeException("Bin $bin does not match any known CC issuer")
}
match.value
}
def computeLuhncheckDigit(def ccnWithoutCheck) {
org.apache.commons.validator.routines.checkdigit.LuhnCheckDigit.LUHN_CHECK_DIGIT.calculate(ccnWithoutCheck)
}
completeCCn('465944') // => 4659441111118
Testing FTW!
Are you benefitting from my writing? Consider buying me a coffee or supporting my work via GitHub Sponsors. Thank you! You can also book me for a mentoring / pair-programming session via Codementor or (cheaper) email.
Allow me to write to you!
Let's get in touch! I will occasionally send you a short email with a few links to interesting stuff I found and with summaries of my new blog posts. Max 1-2 emails per month. I read and answer to all replies.
Recommend
-
30
circle visualization of a number's digits in Go Introduction In the image below, each dot represents a deci...
-
11
Who Gave You Permission To Keep My Credit Card Number? Aug 29, 2016 I've noticed a disturbing trend lately whenever I make a return at a big box store - Lowes,
-
15
Yesterday, I was writing about collecting the mistakes that create interoperability issues in Web brow...
-
6
How to specify fractional digits for formatted number string in Swift Fractional digits are a number of digits after the decimal separator (.). When you want to present a floating...
-
6
Improve Article Reorder digits of a given number to make it a power of 2Difficulty Level : MediumLast Updated : 28 Jun, 2021...
-
7
Improve Article Rotate digits of a given number by KDifficulty Level : EasyLast Updated : 29 Apr, 2021Given two intege...
-
9
Has Your Credit Card Number Been Leaked? By Kinza Yasar Published 7 hours ago The most common type of data breach, a credit card l...
-
12
Validation of the telephone number not having all the digits repeated advertisements I want to validate a telephone number of foramt (xxx) xxx...
-
9
Problem Code:- FLOW006 Problem Statement:- You're given an integer N. Write a program to calculate the sum of all the digits of N. Input The first line contains an integer T, the tot...
-
12
Find First and Last Digits of a Number in PHP ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK