I've written at least 3 versions of this algorithm in various flavors of RPG for the iSeries (AS/400).
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 did too at a previous job where we had a network scanner that could identify (in theory) credit card numbers on the fly as they were accessed or stored into database and file shares.
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 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. ;-)