AbaRoutingNumber Class
Definition
- Namespace
- Bodu.IO.Hashing.CheckDigits
- Assembly
- Bodu.IO.Hashing.dll
- Package
- Bodu.IO.Hashing 1.0.0
- Source
- AbaRoutingNumber.cs
Computes the check digit of a 9-digit American Bankers Association (ABA) routing transit number using the weighted modulus-10 scheme specified by the US Federal Reserve. This class cannot be inherited.
public sealed class AbaRoutingNumber : CheckDigitAlgorithm
- Inheritance
-
AbaRoutingNumber
- Inherited Members
- Extension Methods
Examples
// Single-call computation against the 8-digit body.
char check = AbaRoutingNumber.Compute("01100001"); // '5'
// Full-sequence validation.
bool ok = AbaRoutingNumber.IsValid("011000015"); // true
// Streaming use when the body is built up incrementally.
var algo = new AbaRoutingNumber();
algo.Append("01100001");
char d = algo.GetCurrentCheckDigit(); // '5'
Remarks
The ABA scheme applies the cyclic weight pattern {3, 7, 1} to the first eight digits (weights
3, 7, 1, 3, 7, 1, 3, 7 from left to right). The check digit is chosen so that the full nine-digit sequence
yields a weighted sum that is a multiple of ten.
The static helpers on this type enforce a strict 8-digit body length (9-digit full sequence) to match the ABA specification; the streaming surface is length-agnostic to permit chunked input.
Worked example. For the body "01100001" - the leading 8 digits of the Federal Reserve Bank of Boston's
routing number - the computed check digit is '5', and the resulting sequence "011000015" is therefore
valid.
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
AbaRoutingNumber()
Initializes a new instance of the AbaRoutingNumber class.
public AbaRoutingNumber()
Fields
BodyLength
The required body length of 8 decimal digits.
public const int BodyLength = 8
Field Value
SequenceLength
The required full-sequence length of 9 decimal digits.
public const int SequenceLength = 9
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".
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 ABA routing-number 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'.
Remarks
This helper is length-tolerant to support streaming and partial-body use; IsValid(ReadOnlySpan<char>) enforces the strict SequenceLength domain contract for full validation.
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 an eight-digit body followed by a trailing ABA check digit, is consistent.
public static bool IsValid(ReadOnlySpan<char> digitsIncludingCheck)
Parameters
digitsIncludingCheckReadOnlySpan<char>The complete sequence including the trailing check digit.
Returns
- bool
true if the sequence is exactly SequenceLength digits and evaluates as valid under the ABA scheme; otherwise, false - including the case where
digitsIncludingCheckis empty, the length is wrong, or a non-digit character is present.
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 |