3 ms·
I feel I'm being moronic, and will come back to this in an hour or so once I've finished some work and do the maths again... but I've checked with four cards (t
by corin_ 16y ago
I feel I'm being moronic, and will come back to this in an hour or so once I've finished some work and do the maths again... but I've checked with four cards (two credit cards, two debit cards, all VISA) and none of them result in a number divisible by ten. Results were 107, 98, 107, 106.
Having read http://en.wikipedia.org/wiki/Luhn_algorithm http://en.wikipedia.org/wiki/Luhn_algorithm I'm either doing it right, or I'm way more tired than I thought. Each card number is 16 digits long, so for (from the left) digits 1, 3, etc. I double them, then I add the sum of those doubles to digits 2, 4, etc.
i.e.
1234 1234 1234 1234
Would be:
((1 * 2) + 2 + (3 * 2) + 4) * 4
I feel really dumb for writing that out given it's already written out in this article, and on Wikipedia, but either I am being really dumb or my four cards are all invalid.
EDIT: Here is an old card number (card is long expired), and to be safe I've swapped various numbers around (but only swapped even position numbers with each other, and odd position numbers with each other, so it shouldn't effect the check sum). Could someone kindly tell me if I'm being an idiot?
5658 4612 3826 9730
- akheron 16y agoI get 80 with this number. When you sum, remember to handle two-digit numbers specially, for example 5 * 2 = 10 as 1 and 0, not 10.
- corin_ 16y agoBingo. Well that solves the "none of my cards are valid" conundrum. Now I just need to work out why my mind isn't functioning properly this morning. Cheers!
- gjm11 16y agoI think you've forgotten to reduce individual sums mod 9 (i.e., by adding digits) before adding them up. 5658 4612 3826 9730 [original number] 10 6 10 8 8 6 2 2 6 8 4 6 18 7 6 0 [double alternate digits] 1 6 1 8 8 6 2 2 6 8 4 6 9 7 6 0 [digit sums] 16 18 24 22 [sums of groups] 80 [overall sum] Of course you don't need to bother with the sums-of-groups step; that was just to make it easier for you to notice if I made any mistakes.