lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Wednesday, January 8, 2014, Thijs Schreijer wrote:

The module is a modulo11 number generator and verificator

 

Modulo 11 is a way to calculate checksums for digitbased codes. Common usage for modulo 11 is ISBN, credit card or bank account numbers. The verification offered is not intended for security, but to catch human errors (typo's). See this wikipedia article [1]

 

Modulo 11 calculates a checksum based on a weight given to digits based upon their position. The verifycode must be supplied once, and checking numbers can be done against the same verifycode.

This implementation uses a verifycode 8 characters long, digits 2-9 (no duplicates). This means that for every 8 input digits 1 checksum digit is added. Different series of numbers can be used with different verifycodes.

 

For readability 'allowed' characters can be provided. When calculating or verifying checksums those characters are ignored. Common 'allowed' characters are "-/.". With this set of allowed characters the following sequences will get the same checksums;

 

- 2012.345.67/32

- 2012-345/67.32

- 20123456732

 

Example:

Using an invoicenumber containing a date and a sequential number that can be represented like this: "2013-12-15/015". The allowed characters must be "-/" in this case.

 

local invoice = "2013-12-15/015"

print(m:calc(invoice.."-"))

 

The above example will print the invoice number `2013-12-15/015-xx` where xx is the checksum depending on the verifynumber initially chosen for this sequence.

 

Searching:

The module contains an iterator function that can scan text for valid numbers. Sample use includes checking incoming emails for valid supportcase numbers, or scanning bank transaction details for valid invoice numbers or customerids.

For an example see the `sample.lua` file [4]. The sample contains 2 series with their own verifynumber sequence, where each iterator will only find its own numbers.

 

Details:

Documentation is online [2] as is the source code [3]

Testsuite is included in the `spec` folder and can be executed using busted.

License is MIT

Rockspec has been submitted and after it has landed `luarocks install mod11` will fetch and install the module

 

Comments are welcome

 

Thijs

 

[1] http://en.wikipedia.org/wiki/Check_digit

[2] http://tieske.github.io/mod11

[3] https://github.com/Tieske/mod11

[4] https://github.com/Tieske/mod11/blob/master/samples/sample.lua

 


This looks excellent. Congratulations on the release. However, I'm writing to say that I found this description extremely helpful and will use it as a template for my announcements (for the 3-4 half released projects I've got sitting around).

I liked the background information and the use cases, in particular. So much so, I caught myself trying to think up a reason to need this module. :)

Just some feedback for you!

-Andrew