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