many countries ID cards, credit cards and more.
The purpose is NOT to encrypt the number but prevent simple errors
such as digit misplacement and (usually) single digit errors.
Take the following non-existant Visa credit card number:
This number is correct using the Luhn checksum method, this doesn't mean
you can use it to shop but programmers often use it to perform a preliminary
check prior to sending it on to be approved.
How is the number checked, let's start:
Note that we perform single digit multiplication, top line by bottom line, right to left:
As you can see 8 X 2 is written as 7, if the multiplication gives a value of 10
and above always combine the two digits together (e.g. 10 -> 1+0 = 1)
Since the right digit is 0 the number is correct!
Or in programmers language, 80 mod 10 = 0 means the number is correct, that is why Luhn is
also sometimes called MOD 10 checking.
Lets take a look at an invalid credit card number:
Again from the right column
So, how do you generate a valid number ?!
The right most digit is the check digit which is why we always begin from the right
as described in the check above.
To generate the number we will begin with the digit 2 instead of 1:
NOTE! If the right digit at this stage was 0, then that would be the checkdigit.
Lets check it: