org.thc.shagg.algorithms
Class Modulus10AlgorithmLuhn

java.lang.Object
  |
  +--org.thc.shagg.algorithms.Modulus10Algorithm
        |
        +--org.thc.shagg.algorithms.Modulus10AlgorithmLuhn
All Implemented Interfaces:
CheckDigitAlgorithm
Direct Known Subclasses:
Modulus10AlgorithmCC

public class Modulus10AlgorithmLuhn
extends Modulus10Algorithm

This is "my" definition of the Luhn Algorithm. There are different opinions whether the Luhn Algorithm based on the Modulus 10 Algorithm works like the Basic or the Luhn Classes that have been implemented.

The Luhn Algorithm uses a different Addition. Instead of simply adding two elements, the chain sum of the elements is added, e.g. 10+2 = 3 :)

Version:
$Id: Modulus10AlgorithmLuhn.java,v 1.6 2003/07/18 10:08:05 plasmoid Exp $
Author:
Plasmoid (plasmoid@thc.org), THC

Fields inherited from class org.thc.shagg.algorithms.Modulus10Algorithm
type
 
Constructor Summary
Modulus10AlgorithmLuhn()
           
 
Method Summary
 int mod10Add(int[] sequence, int[] weights, int index)
          Add method for the Modulus 10 Algorithm.
 int mod10checkDigit(int[] sequence)
          Check method for the Modulus 10 Algorithm.
 
Methods inherited from class org.thc.shagg.algorithms.Modulus10Algorithm
check, getCheckDigitPosition, getName, getSymbol, usesWeights
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

Modulus10AlgorithmLuhn

public Modulus10AlgorithmLuhn()
Method Detail

mod10Add

public int mod10Add(int[] sequence,
                    int[] weights,
                    int index)
Add method for the Modulus 10 Algorithm. Elements are added by calculating the chain sum of the multiplied element with the given weights.
Overrides:
mod10Add in class Modulus10Algorithm
Parameters:
sequence - Integer sequence representing the digits to check, not necessary between 0 and 9.
weights - Integer sequence of the weights to use, may be of any length.
index - Current index
Returns:
Sum at index.

mod10checkDigit

public int mod10checkDigit(int[] sequence)
Check method for the Modulus 10 Algorithm. The last digit represents the check digit.
Overrides:
mod10checkDigit in class Modulus10Algorithm
Parameters:
sequence - Integer sequence representing the digits to check, not necessary between 0 and 9.
Returns:
The check digit.