Table of Contents

Isin Class

Definition

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

Computes the check digit of a 12-character International Securities Identification Number (ISIN) using the Luhn-based scheme defined by ISO 6166. This class cannot be inherited.

public sealed class Isin : AlphanumericCheckDigitAlgorithm
Inheritance
Isin
Inherited Members
Extension Methods

Examples

// Apple Inc. - country code US, body "US037833100".
char check = Isin.Compute("US037833100");   // '5'

// Full-sequence validation.
bool ok = Isin.IsValid("US0378331005");     // true

// Streaming use when the body is built up incrementally.
var algo = new Isin();
algo.Append("US037833100");
char d = algo.GetCurrentCheckDigit();       // '5'

Remarks

An ISIN comprises a two-letter country code, a nine-character national security identifier, and a single trailing check digit. To compute the check, every body character is expanded to its numeric value (digits as themselves, 'A'-'Z' to 10-35) and the concatenated string of resulting digits is fed to the standard Luhn algorithm.

Because each letter contributes two digits while each numeral contributes one, the effective digit stream length varies by country-code and body composition. The streaming surface nevertheless preserves prefix-equivalence with Compute(ReadOnlySpan<char>).

Worked example. For the body "US037833100" - Apple Inc. - the computed check digit is '5', and the resulting ISIN "US0378331005" 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

Isin()

Initializes a new instance of the Isin class.

public Isin()

Fields

BodyLength

The required body length of 11 characters.

public const int BodyLength = 11

Field Value

int

SequenceLength

The required full-sequence length of 12 characters.

public const int SequenceLength = 12

Field Value

int

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

body ReadOnlySpan<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 body contains any character outside the algorithm's accepted input alphabet.

Compute(ReadOnlySpan<char>)

Computes the ISIN check digit for the supplied body without allocating a streaming instance.

public static char Compute(ReadOnlySpan<char> body)

Parameters

body ReadOnlySpan<char>

The body characters. Each must be an ASCII decimal digit or uppercase Latin letter.

Returns

char

The check digit as an ASCII character in the range '0' to '9'.

Exceptions

ArgumentOutOfRangeException

Thrown when body contains any character outside '0'-'9' and 'A'- 'Z'.

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 an eleven-character body followed by a single-digit ISIN check, is consistent.

public static bool IsValid(ReadOnlySpan<char> valueIncludingCheck)

Parameters

valueIncludingCheck ReadOnlySpan<char>

The complete twelve-character ISIN.

Returns

bool

true if the sequence evaluates as valid under ISIN; otherwise, false - including the case where valueIncludingCheck is empty, the length is wrong, any body character is outside the alphanumeric uppercase alphabet, or the check character is not a decimal digit.

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

ProductVersions
.NET8, 10