Advertisement
Ikem

Credit.txt

Dec 17th, 2017
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. According to Luhn’s algorithm, you can determine if a credit card number is (syntactically) valid as follows:
  2.  
  3. Multiply every other digit by 2, starting with the number’s second-to-last digit, and then add those products' digits together.
  4.  
  5. Add the sum to the sum of the digits that weren’t multiplied by 2.
  6.  
  7. If the total’s last digit is 0 (or, put more formally, if the total modulo 10 is congruent to 0), the number is valid!
  8.  
  9. That’s kind of confusing, so let’s try an example with my AmEx: 378282246310005.
  10.  
  11. For the sake of discussion, let’s first underline every other digit, starting with the number’s second-to-last digit:
  12.  
  13. 378282246310005
  14.  
  15. Okay, let’s multiply each of the underlined digits by 2:
  16.  
  17. 7•2 + 2•2 + 2•2 + 4•2 + 3•2 + 0•2 + 0•2
  18.  
  19. That gives us:
  20.  
  21. 14 + 4 + 4 + 8 + 6 + 0 + 0
  22.  
  23. Now let’s add those products' digits (i.e., not the products themselves) together:
  24.  
  25. 1 + 4 + 4 + 4 + 8 + 6 + 0 + 0 = 27
  26.  
  27. Now let’s add that sum (27) to the sum of the digits that weren’t multiplied by 2:
  28.  
  29. 27 + 3 + 8 + 8 + 2 + 6 + 1 + 0 + 5 = 60
  30.  
  31. Yup, the last digit in that sum (60) is a 0, so my card is legit!
  32.  
  33. So, validating credit card numbers isn’t hard, but it does get a bit tedious by hand.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement