Skip to main content

get_check_digit

Function get_check_digit 

Source
pub fn get_check_digit(input: &str) -> u8
Expand description

Compute the MRZ check digit for input.

The algorithm:

  1. For each character, map it to a numeric value:
    • ‘A’..‘Z’ -> 10 + (ch - ‘A’)
    • ‘0’..‘9’ -> ch - ‘0’
    • otherwise -> 0
  2. Multiply each value by the repeating weights [7,3,1] at its index.
  3. Sum the products and return (sum % 10) as the check digit.

Example:

assert_eq!(mrz_parser::get_check_digit("L898902C3"), 6);