My favorites | Sign in
Project Logo
                
Show all Featured downloads:
checkdigits-0.9.1.tar.gz
People details
Project owners:
  nickgsuperstar, plinehan

Check digits (or characters) are a 'checksum' on a number or word to help prevent manual typing errors.

This was originally based from Cryptography for Internet and Database Applications, pp 221-229.

This projects provides examples and source in both java and javacript.

Check digits (or characters) are a 'checksum' on a number or word to help prevent manual typing errors. They are not used for long or binary data sets. They are not hashes, nor cryptographic. They do not do error correction. They are for catching CheckDigitsAndManualErrors.

The following schemes are currently implemented:

More information on each is in CheckDigitSystems.

All versions have some type of 'object' with the following methods:

encode Adds check digit to given string
verify Verifies data is correct using check digits
computeCheck Returns the check digit (as integer) for given data
getCheck Extracts the check characters
getData Extracts the data with out the check character

encode may throw an exception if 'bad' data (e.g. non-numeric) is passed to it, while verify only returns true or false. The idea here is that encode normally gets it's data from 'trusted' internal sources (a database key for instance), so it should be pretty usual, in fact, exceptional that bad data is being passed in. verify doesn't throw exceptions since this data is coming from an 'untrusted' source such user input and who knows what they'll type in. Bad input is 'non-exceptional' and is expected.

Note: unless explicitly specified, the code does not check the input length or trim off white space since that is application specific.

The verify method could have been universally implemented as encode(getData(str)) == getCheck(str), however in most caes custom code was implemented. This was done so that:

Java

All check schemes implement the CheckDigit interface.

Extensive Junit tests exist in the com.modp.checkdigits.test package.

Javadoc code is in the java/doc directory.

JavaScript

The javascript versions follow the java code fairly closely. However, the javascript objects do not formally use an interface or use inheritance. They are effectively static classes.

Extensive unit tests exist in the javascript/test directory. Just open the html files in your browser to run the tests.

NOTE: The core of the unit test is based from jsunit, but the test runner is custom. Need to split out the new runner and document it.









Hosted by Google Code