luhn_algo: The Luhn algorithm

Description Usage Arguments Value References Examples

Description

Calculates the control number for a Swedish personal/organisational identity number using the Luhn algorithm.

Usage

1
luhn_algo(id, multiplier)

Arguments

id

Element with swedish personal identity number.

multiplier

What should each element in id be multiplied with

Value

The control number (last digit in the personal identification number) calculated from id (as integer).

References

https://www.skatteverket.se/download/18.8dcbbe4142d38302d74be9/1387372677724/717B06.pdf https://www.skatteverket.se/download/18.1e6d5f87115319ffba380001857/1285595720207/70408.pdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
luhn_algo("121212121212", c(0,0,2,1,2,1,2,1,2,1,2,0))
luhn_algo(  "121212121",  c(      2,1,2,1,2,1,2,1,2))

## If no multiplier, the default is 
## to find one that match the format of id
luhn_algo("121212121212")
luhn_algo("12121212121")
luhn_algo("1212121212")
luhn_algo("121212121")

## Also for multiple pin 
## (as long they are all of the same format)
luhn_algo(c("12121212121", "19850504333"))
## Not run: 
try(luhn_algo(c("12121212121", "850504333"))) ## Different formats should fail!

## End(Not run)


Search within the sweidnumbr package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.