

Rather, the digits were marked in their permuted order on the body of the machine. The substitution digits, that is, the results of the double and reduce procedure, were not produced mechanically.
#Java credit card validator mod#
The device took the mod 10 sum by mechanical means. The algorithm appeared in a United States Patent for a simple, hand-held, mechanical device for computing the checksum. Therefore, systems that pad to a specific number of digits (by converting 1234 to 0001234 for instance) can perform Luhn validation before or after the padding and achieve the same result. The Luhn mod N algorithm is an extension that supports non-numerical strings.īecause the algorithm operates on the digits in a right-to-left manner and zero digits affect the result only if they cause shift in position, zero-padding the beginning of a string of numbers does not affect the calculation. Other, more complex check-digit algorithms (such as the Verhoeff algorithm and the Damm algorithm) can detect more transcription errors.

It will detect most of the possible twin errors (it will not detect 22 ↔ 55, 33 ↔ 66 or 44 ↔ 77). It will not, however, detect transposition of the two-digit sequence 09 to 90 (or vice versa). The Luhn algorithm will detect any single-digit error, as well as almost all transpositions of adjacent digits.

#Java credit card validator software#
Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from mistyped or otherwise incorrect numbers. CreditCardValidator.java / Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. It is not intended to be a cryptographically secure hash function it was designed to protect against accidental errors, not malicious attacks. The algorithm is in the public domain and is in wide use today. The Luhn algorithm or Luhn formula, also known as the " modulus 10" or "mod 10" algorithm, named after its creator, IBM scientist Hans Peter Luhn, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers in the United States, Canadian Social Insurance Numbers, Israeli ID Numbers, South African ID Numbers, Swedish National identification numbers, Swedish Corporate Identity Numbers (OrgNr), Greek Social Security Numbers (ΑΜΚΑ), SIM card numbers, European patent application number and survey codes appearing on McDonald's, Taco Bell, and Tractor Supply Co.
