Generate a few 13 and 16 digit visa card numbers. Please note that this is not meant for fraude etc. because these are still invalid numbers; ie nobody can get money from these accounts. They are just meant for educational purposes and they do pass credit card check, nobody can get money of these numbers though.
;Usage: /creditcard
alias creditcard {
echo -a - | echo -a Creating a few [16] digit visa cards:
var %a = 1 | while (%a <= 10) { echo -a $visa_card_number(16) | inc %a }
echo -a - | echo -a Creating a few [13] digit visa cards:
var %a = 1 | while (%a <= 10) { echo -a $visa_card_number(13) | inc %a }
}
; Visa credit card generator
alias -l visa_card_number {
var %left = 4, %mid, %a = 1
while (%a <= $calc($$1 - 2)) {
%mid = $+(%mid,$rand(0,9))
inc %a
}
; Done with the basic random stuff, now create the last digit that conforms to the 'mod 10 algorithm'
var %body = $reverse($+(%left,%mid)), %a = 1, %b, %n1, %n2
while (%a <= $len(%body)) {
if ($int($calc(%a / 2)) = $calc(%a / 2)) {
%n1 = $calc(%n1 + $mid(%body,%a,1))
}
else {
%b = 2 * $mid(%body,%a,1)
%n2 = $calc(%n2 + $iif(%b > 9, %b - 9, %b))
}
inc %a
}
var %right = $calc(($calc($int($calc((%n1 + %n2) / 10)) + 1) * 10) - (%n1 + %n2))
return $+(%left,%mid,$iif(%right > 9, 0, %right))
}
alias -l reverse {
var %a = $len($$1), %b
while (%a) { %b = $+(%b,$mid($$1,%a,1)) | dec %a }
return %b
}