Iso7064Mod97_10 Class
Definition
- Namespace
- Bodu.IO.Hashing.CheckDigits
- Assembly
- Bodu.IO.Hashing.dll
- Package
- Bodu.IO.Hashing 1.0.0
- Source
- Iso7064Mod97_10.cs
Computes the 2-character check code of an alphanumeric string using the ISO 7064 MOD 97-10 pure algorithm.
This class cannot be inherited.
public sealed class Iso7064Mod97_10 : MultiCharCheckDigitAlgorithm
- Inheritance
-
Iso7064Mod97_10
- Inherited Members
- Extension Methods
Examples
// Single-call computation - returns the two-digit check as a string.
string check = Iso7064Mod97_10.Compute("794"); // "44"
// Full-sequence validation.
bool ok = Iso7064Mod97_10.IsValid("79444"); // true
// Streaming use when the body is built up incrementally.
var algo = new Iso7064Mod97_10();
algo.Append("794");
string code = algo.GetCurrentCheckDigits(); // "44"
Remarks
MOD 97-10 is the pure ISO 7064 system that uses modulus ninety-seven with radix ten. It underpins the
International Bank Account Number (IBAN, ISO 13616), the Legal Entity Identifier (LEI, ISO 17442), and the Committee
on Uniform Securities Identification Procedures (CUSIP) check computation used for Legal-Entity Identifier issuance.
Letters in the body are expanded by value 'A'=10 … 'Z'=35 before being absorbed.
The running remainder r is initialized to zero. Each body character is absorbed as
r ← (r·10 + a) mod 97 for a decimal digit or r ← (r·100 + a) mod 97 for an uppercase letter (whose
value is two decimal digits). The two-digit check code is (98 - (r · 100) mod 97) mod 97, formatted as two
ASCII decimal digits; the complete sequence body + check is valid when its running remainder, including the
check code, equals 1.
Worked example. For the body "794", the computed check code is "44", and the resulting sequence
"79444" is therefore valid under MOD 97-10.
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
Iso7064Mod97_10()
Initializes a new instance of the Iso7064Mod97_10 class.
public Iso7064Mod97_10()
Fields
CheckDigits
The fixed check-code length of 2 decimal digits.
public const int CheckDigits = 2
Field Value
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".
CheckLength
Gets the fixed number of decimal-digit characters emitted as the trailing check code.
public override int CheckLength { get; }
Property Value
- int
A positive integer; for example,
2for 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.
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 97-10 check code for the supplied body without allocating a streaming instance.
public static string Compute(ReadOnlySpan<char> body)
Parameters
bodyReadOnlySpan<char>The body characters. Each must be an ASCII decimal digit or uppercase Latin letter.
Returns
- string
The check code as a string of two ASCII decimal digits.
Exceptions
- ArgumentOutOfRangeException
Thrown when
bodycontains any character outside the alphanumeric uppercase alphabet.
GetCurrentCheckDigits(Span<char>)
Writes the current check code into the supplied destination span.
public override int GetCurrentCheckDigits(Span<char> destination)
Parameters
destinationSpan<char>The span to receive the trailing check characters. Must be at least CheckLength in length.
Returns
- int
The number of characters written, always equal to CheckLength.
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.
Exceptions
- ArgumentException
Thrown when
destinationis shorter than CheckLength.
IsValid(ReadOnlySpan<char>)
Determines whether the supplied sequence, comprising a body followed by a two-digit MOD 97-10 check code, is
consistent - that is, whether its running remainder (with letters expanded and the check code absorbed) equals
1.
public static bool IsValid(ReadOnlySpan<char> valueIncludingCheck)
Parameters
valueIncludingCheckReadOnlySpan<char>The complete sequence including the trailing check code.
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 |