Brasilex.IE.Checksum.Mod9 (Brasilex v0.3.0)

Copy Markdown View Source

Implements the Modulo 9 check digit algorithm used by Roraima (RR).

Algorithm

  1. Multiply each digit by its position (1-indexed from left)
  2. Sum all products
  3. The check digit is the remainder when divided by 9

Example

For IE 24006153 (without check digit):

  • (21) + (42) + (03) + (04) + (65) + (16) + (57) + (38) = 105
  • 105 mod 9 = 6
  • Check digit = 6

Summary

Functions

Calculates the Modulo 9 check digit.

Validates that a string ends with the correct Mod9 check digit.

Functions

calculate(digits)

@spec calculate(String.t()) :: non_neg_integer()

Calculates the Modulo 9 check digit.

Uses weights 1,2,3,4,5,6,7,8 from left to right.

Examples

iex> Brasilex.IE.Checksum.Mod9.calculate("24006153")
6

iex> Brasilex.IE.Checksum.Mod9.calculate("24001755")
6

valid?(digits)

@spec valid?(String.t()) :: boolean()

Validates that a string ends with the correct Mod9 check digit.

Examples

iex> Brasilex.IE.Checksum.Mod9.valid?("240061536")
true

iex> Brasilex.IE.Checksum.Mod9.valid?("240061537")
false