Gumm Class
Definition
- Namespace
- Bodu.IO.Hashing.CheckDigits
- Assembly
- Bodu.IO.Hashing.dll
- Package
- Bodu.IO.Hashing 1.0.0
- Source
- Gumm.Tables.cs
Computes the check digit of a decimal string using the Gumm algorithm. This class cannot be inherited.
public sealed class Gumm : CheckDigitAlgorithm
- Inheritance
-
Gumm
- Inherited Members
- Extension Methods
Examples
// Single-call computation against an in-memory body.
char check = Gumm.Compute("236"); // '9'
// Full-sequence validation.
bool ok = Gumm.IsValid("2369"); // true
// Streaming use when the body is built up incrementally.
var algo = new Gumm();
algo.Append("236");
char d = algo.GetCurrentCheckDigit(); // '9'
Remarks
The Gumm algorithm was presented by H. Peter Gumm in 1985 (A New Class of Check-Digit Methods for Arbitrary Number Systems, IEEE Transactions on Information Theory, 31(1), 102-105). Like the Verhoeff scheme it was discovered independently of, it detects all single-digit substitution errors and all transpositions of adjacent digits using a single decimal check digit.
Those two guarantees are the whole of the scheme's coverage. Gumm does not reliably detect twin errors
(aa → bb): under this instantiation a little over four in ten of them pass validation, which is materially
weaker than Verhoeff or Damm on the same class. Choose Gumm for its simplicity over
Verhoeff, not for broader error coverage.
The method operates in the dihedral group D5 (the symmetries of a regular pentagon, of order 10).
Each digit position carries a permutation of the group; Gumm's contribution over Verhoeff is that these alternate
between the identity and a single transform T rather than requiring position-dependent powers of a
permutation, which is simpler both conceptually and to implement.
This implementation instantiates Gumm's construction over D5 with the transform
T(e, x) = (e, e(2 − x) + 1) and applies the identity permutation at even positions (counted from the right,
so the trailing check digit) and T at odd positions. Both transform parameters are nonzero modulo 5, which is
the condition under which Gumm's anti-symmetry lemma holds and every adjacent transposition is detected. A sequence
(body followed by its check digit) is valid if and only if the accumulated group element is the identity.
Worked example. For the body "236", the computed check digit is '9', and the resulting sequence
"2369" is therefore valid under this instantiation.
important
This algorithm is not cryptographically secure and should not be used for password hashing, digital signatures, or integrity validation in security-sensitive applications.
Constructors
Gumm()
Initializes a new instance of the Gumm class.
public Gumm()
Properties
AlgorithmName
Gets the canonical name of the algorithm, suitable for diagnostic output and logging.
public override string AlgorithmName { get; }
Property Value
- string
A short, stable identifier such as
"Luhn","IBAN", or"ISO 7064 MOD 97-10".
Methods
Append(ReadOnlySpan<char>)
Absorbs the supplied characters into the running check-value state.
public override void Append(ReadOnlySpan<char> body)
Parameters
bodyReadOnlySpan<char>The characters to append. Each element must belong to the algorithm's accepted input alphabet. An empty span is a permitted no-op.
Exceptions
- ArgumentOutOfRangeException
Thrown when
bodycontains any character outside the algorithm's accepted input alphabet.
Compute(ReadOnlySpan<char>)
Computes the Gumm check digit for the supplied body of decimal digits without allocating a streaming instance.
public static char Compute(ReadOnlySpan<char> body)
Parameters
bodyReadOnlySpan<char>The body characters. Each must be an ASCII decimal digit (
'0'to'9').
Returns
- char
The check digit as an ASCII character in the range
'0'to'9'.
Exceptions
- ArgumentOutOfRangeException
Thrown when
bodycontains any character outside the range'0'to'9'.
GetCurrentCheckDigit()
Returns the check digit computed for the body absorbed since the last Reset() (or since construction).
public override char GetCurrentCheckDigit()
Returns
- char
The check digit as an ASCII character in the range
'0'to'9'. For an empty body all built-in algorithms return'0'.
Remarks
This call is non-destructive; the running state is unaffected and the method may be invoked any number of times with identical results between appends.
IsValid(ReadOnlySpan<char>)
Determines whether the supplied sequence, comprising a body followed by a trailing Gumm check digit, is valid - that is, whether the accumulated group element evaluates to the identity.
public static bool IsValid(ReadOnlySpan<char> digitsIncludingCheck)
Parameters
digitsIncludingCheckReadOnlySpan<char>The complete sequence including the trailing check digit.
Returns
Reset()
Resets the algorithm to its initial state, discarding any characters previously absorbed.
public override void Reset()
Remarks
Equivalent in behavior to constructing a fresh instance of the same concrete type.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |