org.thc.shagg.algorithms
Class Modulus10Algorithm
java.lang.Object
|
+--org.thc.shagg.algorithms.Modulus10Algorithm
- All Implemented Interfaces:
- CheckDigitAlgorithm
- Direct Known Subclasses:
- Modulus10AlgorithmBasic, Modulus10AlgorithmLuhn
- public abstract class Modulus10Algorithm
- extends java.lang.Object
- implements CheckDigitAlgorithm
Abstract class for the Modulus 10 Algorithm. The Modulus 10 Algorithm
is the most used check digit algorithm amoung the simple check digit
algorithms. It is even used in critial areas such as credit card and
calling card verification and has caused much fraud in the 90s.
In order to cover the variants of the Modulus 10 Algorithm, this
abstract class was designed as a framework for all variant implementations.
- Version:
- $Id: Modulus10Algorithm.java,v 1.7 2003/07/18 10:08:05 plasmoid Exp $
- Author:
- Plasmoid (plasmoid@thc.org),
THC
Field Summary |
protected java.lang.String |
type
|
Method Summary |
boolean |
check(int[] sequence,
int[] weights)
Checks if the supplied sequence matches the Modulus 10 Algorithm. |
int |
getCheckDigitPosition(int sequence)
Return the check digit position inside the sequence. |
java.lang.String |
getName()
Get the name of the implemented check digit algorithm, Modulus 10. |
java.lang.String |
getSymbol()
Get the symbol of the implemented check digit algorithm. |
abstract int |
mod10Add(int[] sequence,
int[] weights,
int index)
Add method for the Modulus 10 Algorithm. |
abstract int |
mod10checkDigit(int[] sequence)
Check method for the Modulus 10 Algorithm. |
boolean |
usesWeights()
The Modulus 10 Algorithm uses weights. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
type
protected java.lang.String type
Modulus10Algorithm
public Modulus10Algorithm()
getName
public java.lang.String getName()
- Get the name of the implemented check digit algorithm, Modulus 10.
The type field is implemented by the indiviual class extending this
abstract class.
- Specified by:
getName
in interface CheckDigitAlgorithm
- Returns:
- algorithm name.
getSymbol
public java.lang.String getSymbol()
- Get the symbol of the implemented check digit algorithm. In this
case "10" for Modulus 10.
- Specified by:
getSymbol
in interface CheckDigitAlgorithm
- Following copied from interface:
org.thc.shagg.algorithms.CheckDigitAlgorithm
- Returns:
- algorithm symbol
check
public boolean check(int[] sequence,
int[] weights)
- Checks if the supplied sequence matches the Modulus 10 Algorithm.
Modulus uses the provided weights.
- Specified by:
check
in interface CheckDigitAlgorithm
- 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.- Returns:
- wether sequences matches the algorithm.
mod10Add
public abstract int mod10Add(int[] sequence,
int[] weights,
int index)
- Add method for the Modulus 10 Algorithm. The different versions
of the Modulus 10 Algorithm differ in the way the digits are
added.
- 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 abstract int mod10checkDigit(int[] sequence)
- Check method for the Modulus 10 Algorithm. The different versions
of the Modulus 10 Algorithm differ in the way the check digit
is interpreted.
- Parameters:
sequence
- Integer sequence representing the digits to check,
not necessary between 0 and 9.- Returns:
- The check digit.
usesWeights
public boolean usesWeights()
- The Modulus 10 Algorithm uses weights.
- Specified by:
usesWeights
in interface CheckDigitAlgorithm
- Returns:
- true
getCheckDigitPosition
public int getCheckDigitPosition(int sequence)
- Return the check digit position inside the sequence. Modulus 10 uses
the last digit.
- Specified by:
getCheckDigitPosition
in interface CheckDigitAlgorithm
- Parameters:
sequence
- Length of the integer sequence representing the digits
to check, not necessary between 0 and 9.- Returns:
- Position of the check digit.