Return to Video

Luhns Algorithm - Software Testing

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

more » « less
Video Language:
English
Team:
Udacity
Project:
CS258: Software Testing
Duration:
01:39
Udacity Robot edited English subtitles for 05-13 Luhns Algorithm
Udacity Robot edited English subtitles for 05-13 Luhns Algorithm
Gundega added a translation

English subtitles

Revisions Compare revisions