How Credit Card Numbers Are Generated
codytaylor.org
codytaylor.org
Most importantly, the first 6 digits of a Visa numer constitute a "BIN" (Bank Identification Number). I have heard that MasterCard uses variable number of digits for BIN, but I don't have proof. Some places will have lists of BINs (there's really not that many) and reject "card numbers" that don't have a correct BIN.
Secondarily, MasterCard numbers start with "51", "52", "53", "54" or "55". AmEx starts with "34" or "37", and Discover Cards start with "6011" or "650".
Generating a good "fake" CC number is a bit more complex than the first digit, and getting the Luhn checksum correct.
One of the other commentors is correct in having a huge number of checks around the format of a "credit card number". In practice, all kinds of rubbish ends up in the card number field, and every once in a while, it will pass the Luhn checksum and cause problems down stream.
http://en.wikipedia.org/wiki/Credit_card_number
for more details.
The amount of security in a particular system is typically proportional to the value of what is being secured. If the companies using a mere checksum test thought the process needed to be more secure they could do a real authorization against the number.
So, you could, hypothetically, get 1-3 hours of shell internet access based on a generated number.
The most complete one weighs in at 251 lines (175 w/o comments) but it also does a lot of checking to make sure that the CC number matches the CC type.
I'm much happier using Python these days. ;-)
The app I wrote was a few dozen lines of perl and was used as a QA tool. You could tell it to generate X number of credit card numbers, and also specify flags for generating a mix of numbers (all common US and Int'l formats) as well as a mix of valid/invalid numbers (based on checksum data).
It was a fun spend of a couple hours, and it was amazing to determine how simple it was to generate valid numbers, but then they're also useless without CVV, billing zip and street address for the most part.
The latest of these programs was written in vb4, which I could decompile to look at the source (the algorithm wasn't easily available then).