Algorithms >> Luhn

Luhn Algorithm

The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers and Canadian Social Insurance Numbers. It was created by IBM scientist Hans Peter Luhn and described in U.S. Patent 2,950,048 , filed on January 6, 1954, and granted on August 23, 1960.
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. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from collections of random digits.
Language:langu-cpp
IDE:ide-vs-6, ide-vs-8
Test cases:
  1. "0" returns "VALID"
  2. "10" returns "INVALID"
  3. "000" returns "VALID"
  4. "0123456789" returns "INVALID"
  5. "9563051528730297" returns "VALID"
  6. "349084423202500" returns "VALID"
  7. "300084423202500" returns "INVALID"
Download:23rd May 2007 V1.0
VS8 source bin (tinyxml headers and libs)
VS6 source bin (tinyxml headers and libs)
Reference:http://en.wikipedia.org/wiki/Luhn_algorithm
Contact:David Butler
Extra Mile Algo Standard (EMAS) compliant.