Implements the Modulo 9 check digit algorithm used by Roraima (RR).
Algorithm
- Multiply each digit by its position (1-indexed from left)
- Sum all products
- 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
@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
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