0

I've calculated the Luhn's algorithm for all the credit cards and it works fine. The only issue I have is that the American Express cards which are tested don't fulfill the Luhn's algorithm!

This is the Luhn's algorithm as described in the PSET:

  1. Multiply every other digit by 2, starting with the number’s second-to-last digit

  2. Then add those products’ digits together.

  3. Add the sum to the sum of the digits that weren’t multiplied by 2.

4.If the total’s last digit is 0 (or, put more formally, if the total modulo 10 is congruent to 0), the number is valid!

Check it for yourself:

American Express 378282246310005

  1. 6 + 16 + 16 + 4 + 12 + 2 + 0 + 10
  2. 6 + 1 + 6 + 1 + 6 + 4 + 1 + 2 + 2 + 0 + 1 + 0 = 30
  3. 7 + 2 + 2 + 4 + 3 + 0 + 0 = 18
  4. results in checksum: 30 + 18 = 48 !!

American Express 371449635398431 ->

  1. 6 + 2 + 8 + 12 + 10 + 18 + 8 + 2

  2. 6 + 2 + 8 + 1 + 2 + 1 + 0 + 1 + 8 + 8 + 2 = 39

  3. 7 + 4 + 9 + 3 + 3 + 8 + 3 = 37

  4. results in checksum: 39 + 37 = 76 !!

Both don't fulfill the Luhn's Algorithm. Yet they are valid AMEX for testing (https://developer.paypal.com/docs/payflow/payflow-pro/payflow-pro-testing/#testing-guidelines)

Has anyone else encountered this issue?

1

Your calculation must start at the second-to-last digit. The arithmetic you have displayed, starts at the last digit.

From the first example: 378282246310005,

  • the second-to-last digit is 0,

  • step 1 6 + 16 + 16 + 4 + 12 + 2 + 0 + 10 should end with a + 0 (not + 10)

| improve this answer | |
  • In all cases you start with the second-to-last. The second-to-last digit is different for AMEX than for Visa/MC. That is because the lengths are different. That means the starting point is different. Hint Hint. – DinoCoderSaurus Apr 21 at 15:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .