C validating a credit card

This self-checking scheme (referred to as the Luhn Mod-10 Method) is an international standard for validating card account numbers (ISO 2894/ANSI 4.13).

Such account numbers, which cannot exceed 19 digits including the check digit, are assigned, embossed and encoded to include a single check digit in the rightmost position.

Here's how to do it: Step 4 - Add up all the digits in this number (except the checksum) Step 5 - If (sum x 9) MOD 10 = checksum, you have a valid card! If you were to do this in QBASIC, it would look like this: A = 0 FOR X = LEN(CARD$) - 1 TO 1 STEP -2 W = VAL(MID$(CARD$, X,1)) * 2 IF W 1 THEN A = A VAL(MID$(CARD$, X-1, 1)) NEXT X IF (A * 9) MOD 10 = VAL(RIGHT$, CARD$, 1) THEN PRINT "GOOD CARD! " Variables --------- A is the accumulator, adding up the digits on the card, every other one, doubled (doubled -9 if over 9).

CARD$ is the credit card, numeric portion only W is a working variable (temporary to hold the number before added to the accumulator) X is the position of the digit being worked upon, starting at the end of the card number (-1) and working backwards.

Once the actual credit card type is determined, all of the icons fade except the one representing the credit card type.

It was created by IBM scientist Hans Peter Luhn and described in U. The algorithm is in the public domain and is in wide use today. It is not intended to be a cryptographically secure hash function; it was designed to protect against accidental errors, not malicious attacks. I searched and found this: https://en.wikipedia.org/wiki/Luhn_algorithm You were right, up to the checksum/mod test where YOU claim: "If the final sum is divisible by 10, then the credit card number is valid.If it is not divisible by 10, the number is invalid." This is NOT true.The check digit (x) is obtained by computing the sum of the non-check digits then computing 9 times that value modulo 10 (in equation form, ((67 × 9) mod 10)).In algorithm form: This makes the full account number read 79927398713.The ever-so-important difference is that the adjusted card number sum is multiplied by 9 and run through a modula 10 check.

You must have an account to comment. Please register or login here!