1 # The Verhoeff algorithm, for number checksums
3 An implementation of the Verhoeff algorithm.
5 This checksum algorithm is not particularly common (the simpler and somewhat inferior Luhn
6 algorithm is much more widely used, e.g. in credit card numbers), but it definitely gets some
7 use; for example, India’s Aadhaar biometric identity system uses
12-digit numbers as the ID
8 number, with the final digit being a Verhoeff checksum.
10 Background reading: <https://en.wikipedia.org/wiki/Verhoeff_algorithm>
17 use verhoeff::Verhoeff;
18 assert_eq!("12345".calculate_verhoeff_check_digit(), 1);
19 assert!(verhoeff::validate(&[1, 2, 3, 4, 5, 1]));
20 assert!(!"123456".validate_verhoeff_check_digit());
22 use verhoeff::VerhoeffMut;
23 let mut digits = vec![1, 2, 3, 4, 5];
24 digits.push_verhoeff_check_digit();
25 assert_eq!(digits, [1, 2, 3, 4, 5, 1]);
28 ## Cargo.toml usage and features
37 Disabling the
`std` feature to get
`#![no_std]`, but retaining
`alloc` in order to not lose any functionality:
41 verhoeff = { version = "1", default-features = false, features = ["alloc"] }
44 Disabling the
`std` feature without reenabling
`alloc`, thereby losing the implementations of
`VerhoeffMut` (
`push_verhoeff_check_digit`) for
`String` and
`Vec<u8>`:
48 verhoeff = { version = "1", default-features = false }