Table of Contents

AlphanumericCheckDigitAlgorithm Class

Definition

Namespace
Bodu.IO.Hashing.CheckDigits
Assembly
Bodu.IO.Hashing.dll
Package
Bodu.IO.Hashing 1.0.0
Source
AlphanumericCheckDigitAlgorithm.cs

Represents the abstract base class from which single-character check-digit algorithms that operate on a wider input alphabet, or whose check character may be the sentinel 'X', derive.

public abstract class AlphanumericCheckDigitAlgorithm : CheckValueAlgorithm
Inheritance
AlphanumericCheckDigitAlgorithm
Derived
Inherited Members
Extension Methods

Examples

// Use a concrete derivative through the abstract surface - ISIN accepts a mix of
// ASCII letters (the country code) and digits.
AlphanumericCheckDigitAlgorithm algo = new Isin();
algo.Append("US037833100");                          // Apple Inc.
char check = algo.GetCurrentCheckDigit();            // '5'

// Inspect the declared alphabets for input validation upstream.
CheckDigitInputAlphabet  inputs  = algo.InputAlphabet;
CheckDigitOutputAlphabet outputs = algo.OutputAlphabet;

Remarks

Parallel in design to CheckDigitAlgorithm, this base relaxes two constraints: the input may be any subset of ASCII declared by InputAlphabet (decimal digits, or decimal digits and uppercase Latin letters), and the emitted check character may be any value of OutputAlphabet - notably including the 'X' sentinel used by ISBN-10 and ISO 7064 MOD 11-2 to represent the check value ten.

Like the rest of this family, the type is intentionally separate from the byte-stream oriented NonCryptographicHashAlgorithm and does not derive from it. A non-cryptographic hash produces a fixed-length opaque byte digest over arbitrary input; a check character performs error detection over a constrained ASCII text alphabet and emits a single char. The families are kept distinct by design rather than unified under one base type.

The streaming surface - Append(ReadOnlySpan<char>), Reset(), and GetCurrentCheckDigit() - will nonetheless feel familiar to anyone who has used a hash algorithm: input is accumulated, the computation can be restarted, and reading the current check character is non-destructive and idempotent. That resemblance is incidental convenience, not a shared contract. Concrete implementations document their empty-body behavior.

Instances are not thread-safe. Each thread that needs a running check should construct its own instance.

important

Check-digit algorithms are error-detection primitives, not cryptographic functions. They must not be used for password hashing, digital signatures, or integrity validation in security-sensitive applications.

Constructors

AlphanumericCheckDigitAlgorithm()

Initializes a new instance of the AlphanumericCheckDigitAlgorithm class.

protected AlphanumericCheckDigitAlgorithm()

Properties

InputAlphabet

Gets the subset of ASCII from which this algorithm accepts body characters.

public abstract 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 abstract CheckDigitOutputAlphabet OutputAlphabet { get; }

Property Value

CheckDigitOutputAlphabet

The declared output alphabet.

Methods

GetCurrentCheckDigit()

Returns the check character computed for the body absorbed since the last Reset() (or since construction).

public abstract 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.

GetCurrentCheckValue()

Returns the check value computed for the body absorbed since the last Reset() (or since construction) as a newly allocated string.

public override sealed string GetCurrentCheckValue()

Returns

string

A string of length CheckLength containing the check value.

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. The single-character branches also expose the result as a char via GetCurrentCheckDigit(), which avoids the string allocation.

Applies to

ProductVersions
.NET8, 10

See Also