Title: | Implementation of the 'Verhoeff' Check Digit Algorithm |
---|---|
Description: | An implementation of the 'Verhoeff' algorithm for calculating check digits (Verhoeff, J. (1969) <doi:10.1002/zamm.19710510323>). Functions are provided to calculate a check digit given an input number, calculate and append a check digit to an input number, and validate that a check digit is correct given an input number. |
Authors: | Conor Neilson |
Maintainer: | Conor Neilson <[email protected]> |
License: | GPL-3 |
Version: | 0.4.0.9000 |
Built: | 2024-11-19 05:10:59 UTC |
Source: | https://github.com/condwanaland/verhoeff |
Calculates a single Verhoeff Check Digit. This function is exported, but it would usually be called from one of the 'verhoeff_*' wrapper functions
calculate_digit(number, d5, d5_p, inv_v)
calculate_digit(number, d5, d5_p, inv_v)
number |
A number you want to calculate the check digit for |
d5 |
The verhoeff d5 matrix. Retrievable with create_verhoeff_matrices()$d5 |
d5_p |
The verhoeff p matrix. Retrievable with create_verhoeff_matrices()$d5_p |
inv_v |
The verhoeff inv matrix. Retrievable with create_verhoeff_matrices()$inv_v |
A single integer
dat <- verhoeff::create_verhoeff_matrices() calculate_digit(5, dat$d5, dat$d5_p, dat$inv_v)
dat <- verhoeff::create_verhoeff_matrices() calculate_digit(5, dat$d5, dat$d5_p, dat$inv_v)
Takes a number and prepares it for input to the verhoeff algorithim by reversing it
prepare_number(number)
prepare_number(number)
number |
A single number that can be coerced to numeric |
A numeric vector of length equal to number of digits in the input
prepare_number(1234)
prepare_number(1234)
Return a number with its check digit appended
verhoeff_append(number, sep = "-")
verhoeff_append(number, sep = "-")
number |
The number to calculate a check digit for |
sep |
A separator for the two numbers |
Numeric vector of length equal to its input
verhoeff::verhoeff_append(123)
verhoeff::verhoeff_append(123)
verhoeff_calculate
verhoeff_calculate(number, as_list = FALSE)
verhoeff_calculate(number, as_list = FALSE)
number |
The vector of numbers you want a check digit for |
as_list |
Return the results as a list? Defaults to false |
Vector or list of check digits
verhoeff_calculate(1234)
verhoeff_calculate(1234)
Enter a number, and an existing check digit. Function will return true if the supplied check digit is a correct verhoeff check digit for the given number
verhoeff_validate(number, check_digit)
verhoeff_validate(number, check_digit)
number |
A numerical input |
check_digit |
An existing check digit for the input number |
Logical vector
verhoeff::verhoeff_validate(123, 3)
verhoeff::verhoeff_validate(123, 3)