Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. Before a credit card is submitted to a financial institution, it generally makes sense to run some simple reality checks on the number. The numbers are a good length and it's common to make minor transcription errors when the card is not scanned directly.
  2. The first check people often do is to validate that the card matches a known pattern from one of the accepted card providers. Some of these patterns are:
  3. ```
  4. +============+=============+===============+
  5. | Card Type | Begins With | Number Length |
  6. +============+=============+===============+
  7. | AMEX | 34 or 37 | 15 |
  8. +------------+-------------+---------------+
  9. | Discover | 6011 | 16 |
  10. +------------+-------------+---------------+
  11. | MasterCard | 51-55 | 16 |
  12. +------------+-------------+---------------+
  13. | Visa | 4 | 13 or 16 |
  14. +------------+-------------+---------------+
  15. ```
  16. All of these card types also generate numbers such that they can be validated by the Luhn algorithm, so that's the second check systems usually try.
  17.  
  18. 1. The steps are:
  19. 1. Starting with the next to last digit and continuing with every other digit going back to the beginning of the card, double the digit
  20. 1. Sum all doubled and untouched digits in the number
  21. 1. If that total is a multiple of 10, the number is valid
  22.  
  23. 1. For example, given the card number 4408 0412 3456 7893:
  24. 1. 8 4 0 8 0 4 2 2 6 4 10 6 14 8 18 3
  25. 1. 8+4+0+8+0+4+2+2+6+4+1+0+6+1+4+8+1+8+3 = 70
  26. 1. 70 % 10 == 0 #=> Thus that card is valid.
  27.  
  28. 1. Let's try one more, 4417 1234 5678 9112:
  29. 1. 8 4 2 7 2 2 6 4 10 6 14 8 18 1 2 2
  30. 1. 8+4+2+7+2+2+6+4+1+0+6+1+4+8+1+8+1+2+2 = 69
  31. 1. 69 % 10 != 0 #=> That card is not valid.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement