Luhn Algorithm

Luhn
Find and Compare prices on luhn at Smarter.com.
www.smarter.com

Luhn algorithm - Wikipedia, the free encyclopedia
The Luhn algorithm will detect any single-digit error, as well as almost all ... The Luhn mod N algorithm is an extension that supports non-numerical strings. ...
en.wikipedia.org

EE4253 LUHN-10 Secrets
Secrets of the LUHN-10 Algorithm - An Error Detection Method ... algorithms for character-based error control is known as the LUHN-10 Algorithm. ...
www.ee.unb.ca

Luhn mod N algorithm - Wikipedia, the free encyclopedia
The Luhn mod N algorithm generates a check digit (more precisely, a check ... approach (akin to the original Luhn algorithm) is to use ASCII code arithmetic. ...
en.wikipedia.org

Anatomy of Credit Card Numbers
The most succint description of the Luhn algorithm I have found comes from the ... credit card number using Luhn algorithm //-public abstract class LuhnCheck ...
www.merriampark.com

Luhn Check - MOD 10 Algorithm
The luhn algorithm is primarily used for the validation of credit card numbers, ... The Luhn algorithm is not exclusive to credit cards, it can also be used for ...
www.intermedia-online.com

How To Generate *Valid* Credit Card Numbers - Money, Matter, and More ...
What do the credit card numbers mean and how are they generated? ... In 1954, Hans Luhn of IBM proposed an algorithm to be used as a validity ...
www.thetaoofmakingmoney.com

Check Digit Algorithm - OpenMRS
We have borrowed the variation on the Luhn algorithm used by Regenstrief Institute, Inc. ... So, here's how we would use the Luhn algorithm for the identifier "139MT" ...
openmrs.org

Algorithm::LUHN - Calculate the Modulus 10 Double Add Double checksum ...
Algorithm::LUHN - Calculate the Modulus 10 Double Add Double checksum. SYNOPSIS ... If NUM is not valid, $Algorithm::LUHN::ERROR will contain the reason. ...
search.cpan.org

Algorithms | Business by numbers | Economist.com
Consumers and companies increasingly depend on a hidden mathematical world ... The Luhn algorithm performs a simple ... Wikipedia describes the Luhn algorithm. ...
www.economist.com




Warning: mkdir() [function.mkdir]: Permission denied in /home/webs/affiliatelib2/CacheManager.php on line 12

Warning: mkdir() [function.mkdir]: No such file or directory in /home/webs/affiliatelib2/CacheManager.php on line 12

Warning: fopen(/home/templatecore2cache//*cluesnet.com/58/588bcebab316ca45d2245396157286c028b633bb.tc2cache) [function.fopen]: failed to open stream: No such file or directory in /home/webs/affiliatelib2/CacheManager.php on line 130

Warning: fwrite(): supplied argument is not a valid stream resource in /home/webs/affiliatelib2/CacheManager.php on line 131

Warning: fclose(): supplied argument is not a valid stream resource in /home/webs/affiliatelib2/CacheManager.php on line 132



The Luhn algorithm or Luhn formula, also known as the "modular arithmetic 10" or "mod 10" algorithm,is a simple checksum formula used to validate a variety of identification numbers, such as credit card#Credit card numbering and Canada Social Insurance Numbers. It was created by IBM scientist Hans Peter Luhn and described in , 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 cryptographic 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.

Informal explanation The formula verifies a number against its included check digit, which is usually appended to a partial account number to generate the full account number. This account number must pass the following test:

  • Counting from rightmost digit (which is the check digit) and moving left, double the value of every second digit. For any digits that thus become 10 or more, subtract 9 from the result. For example, 1111 becomes 2121, while 8763 becomes 7733 (from 2×6=12 → 12-9=3 and 2×8=16 → 16-9=7).
  • Add all these digits together. For example, if 1111 becomes 2121, then 2+1+2+1 is 6; and 8763 becomes 7733, so 7+7+3+3 is 20.
  • If the total ends in 0 (put another way, if the total modulus 10 is congruent to 0), then the number is valid according to the Luhn formula; else it is not valid. So, 1111 is not valid (as shown above, it comes out to 6), while 8763 is valid (as shown above, it comes out to 20).


  • Strengths and weaknesses The Luhn algorithm will detect any single-digit error, as well as almost all transpositions of adjacent digits. It will not, however, detect transposition of the two-digit sequence 09 to 90 (or vice versa). Other, more complex check-digit algorithms (such as the Verhoeff algorithm) can detect more transcription errors. The Luhn mod N algorithm is an extension that supports non-numerical strings.

    Because the algorithm operates on the digits in a right-to-left manner and zero digits only affect the result if they cause shift in position, zero-padding the beginning of a string of numbers does not affect the calculation. Therefore, systems that normalize to a specific number of digits by converting 1234 to 00001234 (for instance) can perform Luhn validation before or after the normalization and achieve the same result.

    The algorithm appeared in a US Patent for a hand-held, mechanical device for computing the checksum. It was therefore required to be rather simple. The device took the mod 10 sum by mechanical means. The substitution digits, that is, the results of the double and reduce procedure, were not produced mechanically. Rather, the digits were marked in their permuted order on the body of the machine.For more information click here http://www.luhn-algorithm.com

    Example Consider the example identification number 446-667-651. The first step is to double every other digit, counting from the second-to-last digit and moving left, and sum the digits in the result. The following table shows this step (highlighted rows indicating doubled digits):

    {| class="wikitable"! Digit !! Double !! Reduce !! Result|-align=center| 1 || || 1 || 1|-align=center style="background: #FFA;"| 5 || 10 ||10-9 || 1|-align=center| 6 || || 6 || 6|- align=center style="background: #FFA;"| 7 || 14 || 14-9 || 5|-align=center| 6 || || 6 || 6|- align=center style="background: #FFA;"| 6 || 12 || 12-9 || 3|-align=center| 6 || || 6 || 6|- align=center style="background: #FFA;"| 4 || 8 || 8 || 8|-align=center| 4 || || 4 || 4|-align=center| colspan="3" | Total Sum: || 40|}

    The sum of 40 is divided by 10; the remainder is 0, so the number is valid.

    A lookup table (i.e. calculate Double, Reduce, and Sum of digits only once and for all) can be used (0123456789 is mapped to 0246813579)

    {| class="wikitable"! Digit !! Double !! Reduce !! Result|-| 0 || 0 || 0 || 0|-| 1 || 2 || 2 || 2|-| 2 || 4 || 4 || 4|-| 3 || 6 || 6 || 6|-| 4 || 8 || 8 || 8|-| 5 || 10 || 10-9 || 1|-| 6 || 12 || 12-9 || 3|-| 7 || 14 || 14-9 || 5|-| 8 || 16 || 16-9 || 7|-| 9 || 18 || 18-9 || 9|}

    Implementation This C Sharp function implements the algorithm described above, returning true if the given array of digits represents a valid Luhn number, and false otherwise.

    bool CheckNumber(int digits) { int sum = 0; bool alt = false; for(int i = digits.Length - 1; i >= 0; i--) { if(alt) { digitsi *= 2; if(digitsi > 9) { digitsi -= 9; } } sum += digitsi; alt = !alt; } return sum % 10 == 0; }

    The following is an algorithm (in C Sharp) to generate a number that passes the Luhn algorithm. It fills an array with random digits then computes the sum of those numbers as shown above and places the difference 10-sum (modulo 10) in the last element of the array.

    int CreateNumber(int length) { Random random = new Random(); int digits = new intlength; // For loop keeps default value of zero for last slot in array for(int i = 0; i < length - 1; i++) { digitsi = random.Next(10); } int sum = 0; bool alt = true; for(int i = length - 2; i >= 0; i--) { if(alt) { int temp = digitsi; temp *= 2; if(temp > 9) { temp -= 9; } sum += temp; } else { sum += digitsi; } alt = !alt; } int modulo = sum % 10; if(modulo > 0) { digitslength-1 = 10 - modulo; } // No else req'd - keep default value of zero for digitslength-1 return digits; }

    Other implementations

    References





     
    Copyright © 2008 opini8.com - All rights reserved.
    Home | Terms of Use | Privacy Policy
    All Trademarks belong to their repective owners.
    Many aspects of this page are used under
    commercial commons license from Yahoo!