Many of us from the pre-stripe era have implemented Luhn once or twice I'd say, very often in Javascript and web scripting languages! However, you really should avoid re-implementing this sort of thing, and particularly additional credit card checks as it's easy to make spurious assumptions (eg. credit card prefix should equal country of address of credit card, or of mailing address) which are in fact invalid. This stuff prevents actual sales and frustrates your users.<p>For a slightly out there and arguably more interesting financial checksum algorithm, and one that is actually amazingly effective, do some statistics on mod97's performance. Realizing how good it was, a few years back for a cool hack in my IBAN library I wrote a mistranscription error suggestion system, which plays off the strengths of mod97. See <a href="https://github.com/globalcitizen/php-iban/blob/master/trunk/php-iban.php#L320" rel="nofollow">https://github.com/globalcitizen/php-iban/blob/master/trunk/...</a> and <a href="https://github.com/globalcitizen/php-iban/blob/master/trunk/mistranscriptions.txt" rel="nofollow">https://github.com/globalcitizen/php-iban/blob/master/trunk/...</a> - for a quick hack, it's amazingly effective.<p>PS. I am available for remote gigs doing creative or challenging stuff in finance-land at the moment, if anyone appreciates this sort of thing.
The first time I've seen the Luhn algorithm was on a compromised web server. The cracker has put several fake ebay login/registration pages, as well as a couple of Javascript files.<p>The pages were obviously intended to be used for phishing. However, what really made me go "wow" was the extra mile they went: one of the Javascript files contained methods that took the credit card number from the fake registration page and checked its validity w/ the Luhn algorithm before emailing it to a random email address. If the number was invalid, the user got an error and they forced him to re-enter.<p>I didn't know about the algorithm at the time (this was around 2005), so I was a bit baffled what the heck they are trying to do.
I find the most interesting thing about the algorithm is that, as mentioned in the article, it was originally designed to be computable by a simple mechanical device.
I had come across this while generating test credit card credentials while integrating a payment gateway. Had written a small Python utility for that. Here - <a href="https://github.com/ratpik/luhn" rel="nofollow">https://github.com/ratpik/luhn</a>
I wrote a bit of code that generates a random number that passes the Luhn test.[0] It was one of those random things I did in high school when I was learning to program.<p>[0]: <a href="http://bradconte.com/cc_generator" rel="nofollow">http://bradconte.com/cc_generator</a>
Luhn is also used for the last digit in Swedish social security numbers, <a href="https://en.wikipedia.org/wiki/Personal_identity_number_%28Sweden%29#Checksum" rel="nofollow">https://en.wikipedia.org/wiki/Personal_identity_number_%28Sw...</a>
which makes me remember doing this in school around age of 10. i wish the teacher then would call it an "algorithm", so one wouldnt grow up thinking "algorithms" is something complex and hard to understand
This was great for getting a free month of AOL every month for years back when that was how many people connected to the internet. You just came up with a fake number that worked with this algorithm and you were good. There were even lots of automated applications to do that for you near the end such as AOHell:
<a href="https://en.wikipedia.org/wiki/AOHell" rel="nofollow">https://en.wikipedia.org/wiki/AOHell</a>
There's also the Damm algorithm[1], which is similar but better.
[1]: <a href="https://en.wikipedia.org/wiki/Damm_algorithm" rel="nofollow">https://en.wikipedia.org/wiki/Damm_algorithm</a>
I came to know about this algorithm while solving Ruby Quiz[0]. Simple yet powerful
[0]: <a href="http://rubyquiz.com/quiz122.html" rel="nofollow">http://rubyquiz.com/quiz122.html</a>