luhn

package module
v0.0.0-...-b1c12d6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2021 License: MIT Imports: 2 Imported by: 9 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-luhn

Luhn control digit calculation for Go.

About the Luhn algorithm

The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, named after its creator, IBM scientist Hans Peter Luhn, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers in the United States, Canadian Social Insurance Numbers, Israeli ID Numbers, South African ID Numbers, Greek Social Security Numbers (ΑΜΚΑ), and survey codes appearing on McDonald's, Taco Bell, and Tractor Supply Co. receipts. It is described in U.S. Patent No. 2,950,048, filed on January 6, 1954, and granted on August 23, 1960.

The algorithm is in the public domain and is in wide use today. It is specified in ISO/IEC 7812-1.[1] It is not intended to be a cryptographically secure hash function; it was designed to protect against accidental errors, not malicious attacks. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from mistyped or otherwise incorrect numbers.

– Wikipedia

Usage

package main

import (
    luhn "github.com/EClaesson/go-luhn"
)

func main() {
    control, err := luhn.GetControlDigit("012345")
    // control is 5

    valid, err := luhn.IsValid("0123455")
    // valid is true

    valid, err := luhn.IsValid("0123456")
    // valid is false
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetControlDigit

func GetControlDigit(num string) (int, error)

GetControlDigit calculates the control digit of a string of digits.

func IsValid

func IsValid(num string) (bool, error)

IsValid checks whether the passed control digit (last digit in string) is correct.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址