/luhn_ex

Luhn algorithm for Elixir

Primary LanguageElixirMIT LicenseMIT

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 version hex.pm daily downloads hex.pm weekly downloads hex.pm downloads Build 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:

  • ☑ CI for latest Elixir
  • ☑ Property tests
  • ☑ Compute check digit
  • ☑ Append check digit
  • ☑ Octal & Hexadecimal support

hex.pm version Elixir 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

# Append check digit
Luhn.append_check_digit("37828224631000") 
"378282246310005"

Benchmarking

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

Author

Takayuki Matsubara (@ma2ge on twitter)

LICENSE

MIT