org.jcoderz.commons.util
Class LuhnAlgorithm

java.lang.Object
  extended by org.jcoderz.commons.util.LuhnAlgorithm

public final class LuhnAlgorithm
extends Object

The Luhn algorithm. The Luhn algorithm or Luhn formula, also known as the modulus 10 or mod 10 algorithm, was developed in the 1960s as a method of validating identification numbers. It is a simple checksum formula used to validate a variety of account numbers, such as credit card numbers and Canadian Social Insurance Numbers. Much of its notoriety comes from credit card companies' adoption of it shortly after its creation in the late 1960s by IBM scientist Hans Peter Luhn (1896-1964). 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 protects against random error, not malicious attack. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from collections of random digits.

Author:
Michael Griffel

Method Summary
static boolean check(String cardNumber)
          Execute the Luhn (Mod10) card check on a given card number.
static int computeLuhnCardNumber(String cardNumberWithoutLastDigit)
          Computes the Luhn check digit for a given card number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

check

public static boolean check(String cardNumber)
Execute the Luhn (Mod10) card check on a given card number.

Parameters:
cardNumber - the card number to check.
Returns:
true if the Luhn check succeeds; false otherwise.

computeLuhnCardNumber

public static int computeLuhnCardNumber(String cardNumberWithoutLastDigit)
Computes the Luhn check digit for a given card number.

Parameters:
cardNumberWithoutLastDigit - the card number without the last digit.
Returns:
the Luhn check digit for the given card number.


Copyright 2007 The jCoderZ Project.