Luhn Algorithm

Validate a variety of numbers such as credit cards and national identification numbers with the Luhn alogrithm published in 1960 by Hans Peter Luhn.

hex.pm versionhex.pm daily downloadshex.pm weekly downloadshex.pm downloadsBuild Status

The original v0.3.3 by Takayuki Matsubara only validated numbers and is available at {:luhn, "~> 0.3.3"}.

This fork is available at {:luhn60, "~> 1.3"} and has these enhancements:

hex.pm versionElixir CI

Installation

This fork:

{:luhn60, "~> 1.3"}

Original:

{:luhn, "~> 0.3"}

How to use

# validate number
Luhn.valid? "378282246310005"
# => true

# Integer type number
Luhn.valid? 378282246310005
# => true

# Compute check digit
Luhn.compute_check_digit("37828224631000")
# => 5

Benchmarking

$ MIX_ENV=bench mix deps.get
$ MIX_ENV=bench mix compile
$ mix bench

Author

Takayuki Matsubara (@ma2ge on twitter)

LICENSE

MIT