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