Iso7064Mod11_2 Class
Definition
- Namespace
- Bodu.IO.Hashing.CheckDigits
- Assembly
- Bodu.IO.Hashing.dll
- Package
- Bodu.IO.Hashing 1.0.0
- Source
- Iso7064Mod11_2.cs
Computes the single-character check of a decimal string using the ISO 7064 MOD 11-2 pure algorithm. This
class cannot be inherited.
public sealed class Iso7064Mod11_2 : AlphanumericCheckDigitAlgorithm
- Inheritance
-
Iso7064Mod11_2
- Inherited Members
- Extension Methods
Examples
// Single-call computation against a decimal body.
char check = Iso7064Mod11_2.Compute("0794"); // '0'
// Full-sequence validation.
bool ok = Iso7064Mod11_2.IsValid("07940"); // true
// Streaming use when the body is built up incrementally.
var algo = new Iso7064Mod11_2();
algo.Append("0794");
char d = algo.GetCurrentCheckDigit(); // '0'
Remarks
MOD 11-2 is the pure ISO 7064 system that uses modulus eleven with radix two. It operates on an arbitrary
sequence of decimal digits and emits a single check character drawn from the alphabet '0'-'9' plus the
sentinel 'X' used to represent the value ten.
The working digit is initialized to zero, and for each body digit a it is updated as
p ← ((p + a) × 2) mod 11. The check character is chosen so that (p + c) mod 11 = 1, i.e.
c = (12 - p) mod 11; the sequence body + c is valid when the same identity holds.
Worked example. For the body "0794", the computed check character is '0', and the resulting
sequence "07940" is therefore valid under MOD 11-2.
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
Iso7064Mod11_2()
Initializes a new instance of the Iso7064Mod11_2 class.
public Iso7064Mod11_2()
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".
InputAlphabet
Gets the subset of ASCII from which this algorithm accepts body characters.
public override CheckDigitInputAlphabet InputAlphabet { get; }
Property Value
- CheckDigitInputAlphabet
The declared input alphabet.
OutputAlphabet
Gets the subset of ASCII from which this algorithm may emit its check character.
public override CheckDigitOutputAlphabet OutputAlphabet { get; }
Property Value
- CheckDigitOutputAlphabet
The declared output alphabet.
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 ISO 7064 MOD 11-2 check character for the supplied body of decimal digits without allocating a streaming instance.
public static char Compute(ReadOnlySpan<char> digits)
Parameters
digitsReadOnlySpan<char>The body characters. Each must be an ASCII decimal digit (
'0'to'9').
Returns
- char
The check character, either an ASCII decimal digit or the sentinel
'X'.
Exceptions
- ArgumentOutOfRangeException
Thrown when
digitscontains any character outside the range'0'to'9'.
GetCurrentCheckDigit()
Returns the check character computed for the body absorbed since the last Reset() (or since construction).
public override char GetCurrentCheckDigit()
Returns
- char
The check character as an ASCII character drawn from OutputAlphabet.
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 ISO 7064 MOD 11-2 check character, is consistent.
public static bool IsValid(ReadOnlySpan<char> valueIncludingCheck)
Parameters
valueIncludingCheckReadOnlySpan<char>The complete sequence including the trailing check character.
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 |