Giri

Giri

Luhn Check Algorithm

After trying forever to find out who or what to actually blog about, read a quote somewhere about blogging to learn rather than teach. It somehow freed up a burden of responsibility from my shoulders.

So hope fully this is the first of many. Let's start by implementing the luhn checksum algorithm. This one should be familiar from a number of different contexts, including credit card numbers.

A checksum is a string generated from data which is used to verify the data integrity when the data is either stored or transmitted. The function used to generate this checksum is called the checksum algorithm or function. The luhn algorithm in it's most common form is the described for modulo 10, but can be extended upto modulo N.

The algorithm generates a check code that can be used to detect errors of the form of "ab" -> "ba".

The same is implemented in golang below, with the rust implementation sometime later. The code is at present not optimised and switching between bases at present requires switching the implementation of the codebook generation.

Other Links :

  • A much better explanation than I can manage. http://blogs.ubc.ca/carmenbrunitaap2014/files/2014/03/Luhns-Algorithm.pdf

Implementation :

  • Golang : https://github.com/ace03uec/luhngo