Now what we do is we sum up all of these digits that we've derived at--that is to say
the odd number of digits we just summed up, the even number of digits we summed up,
the results of these calculations, and then we compute the value Mod 10--that is to say
we just took the 1s digit of the sum and if that value was equal to 0, you have a valid credit number.
If the value does not come out to be 0, then it's invalid.
Okay. So that was the case for the odd number of digits.
Now, let's briefly look at the case for an even number of digits and that's almost the same.
So if we have an even number of digits, we go ahead and take
the odd number of digits, double them, and we'll try it now..
If the doubled number ends up being 10 or higher, then after that the process is the same.
We add them up, take the 1s digit or equivalently take the sum Mod 10 and see if the result is 0.
So that is Luhn's algorithm, and the reason that we need to go over that in a bit of painstaking detail
is because if you want to generate valid credit car numbers, then you're going to need to implement
Luhn's algorithm in order to do that, and so there's one little detail that I left off.
And so what I just told you is way to check whether the number is valid
and what you're going to need to do is create a valid credit card number.
So you're going to be given the issue identifier, you're going to make up the account number
randomly, and then what you're going to do is put a 0 at the end of the credit card number,
use Luhn's algorithm to compute the check sum for it and the result of that is unlikely to be 0.
If the check sum comes out to be 0, then you've already generated a valid credit number.
If it hasn't, then you're going to have to take 10 to track the check sum from 10
and put whatever number you arrived at in the place of the check sum digit where you had 0
and now you have a valid credit card number, and I suggest that as you're implementing this
you check it--so you compute the Luhn number.
If it's not 0, you subtract it from 10, put that in the check sum position, and now you can go ahead
and compute the check sum of the entire credit card number--it need to come out 0