luhn3-1.0.4 has been yanked.
Validates strings and computes check digits using the Luhn algorithm.
This is a fast, allocation and panic free crate for computing and validating Luhn checksum for decimal and alpha numeric sequences. This is my crate. There are many like it, but this one is mine.
It's not a great checksum, but it's used in a bunch of places:
- credit card numbers
- International Securities Identification Number (ISIN) codes
- International Mobile Equipment Identity (IMEI) codes
- Canadian Social Insurance Numbers
More information is available on wikipedia.
Usage
Add luhn3 under [dependencies] in your Cargo.toml:
[]
= "1.0"
Most of the CC numbers use Luhn checksum:
// Visa
valid; // true
// MasterCard
valid; // true
// Invalid Visa
valid; // false
Library also allows to calculate a checksum if missing:
// Take off the checksum from American Express card number
let = b"378282246310005".split_last.unwrap;
// and recalculate it
checksum; // Some(b'5')
This library provides two sets of operation: [decimal] and [alphanum].
decimaloperates on sequences composed of decimal numbers only, such as credit card numbers orIMEIcodesalphanumoperates on sequences composed of decimal numbers and capital latin letters, such asISINorNSIN
no_std
Crate doesn't use std
Performance
Library contains scalar implementations for both decimal and alhpanumeric inputs and vectorized implementation for decimal inputs.
validate isin time: [13.136 ns 13.181 ns 13.230 ns]
validate visa time: [13.523 ns 13.572 ns 13.627 ns]
validate visa vec time: [6.6799 ns 6.7189 ns 6.7671 ns]