Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Mod 11 Check digit routine

89 views
Skip to first unread message

Peter Lacey

unread,
Feb 7, 1995, 12:58:00 AM2/7/95
to
Does anyone have a decent mod-11 check digit routine? The one in the
Microfocus canon could be improved on, I think.
Thanks.

Boyce G. Williams

unread,
Feb 7, 1995, 11:49:12 AM2/7/95
to
la...@access.mbnet.mb.ca (Peter Lacey) writes:

You might examine Welburn's "Advanced Structured COBOL" page
387. It gives a good step-by-step verbal procedure on the
process that can easily translate to code.

Good luck,
Boyce Williams

David K. Bryant

unread,
Feb 7, 1995, 11:57:34 PM2/7/95
to
la...@access.mbnet.mb.ca (Peter Lacey) writes:

> Does anyone have a decent mod-11 check digit routine? The one in the
>Microfocus canon could be improved on, I think.

Mod-11? Don't know it by that name.

I have one that written to calculate the checkdigit for UPC-A and
and one for credit cards and bank accounts. Double-add-double-excess-10.

Actually its the same routine with just a different weight table
for each and a test to handle the carry.

Compact and in heavy daily use.


David K. Bryant

unread,
Feb 25, 1995, 12:05:31 AM2/25/95
to
sbpa...@moe.coe.uga.edu (Sheila B. Parker) writes:

>Peter Lacey (la...@access.mbnet.mb.ca) wrote:
>: Does anyone have a decent mod-11 check digit routine?

>No code here (I'll see what I can do, if you want) but the simplest
>MOD 11 is an alternating sum of the digits. You start with the low-order
>digit and alternately add and subtract digits as you go, like this:

> 1245237 MOD 11 => 7 - 3 + 2 - 5 + 4 - 2 + 1 => 4

>This gives you a number that is equivalent (MOD 11) to the original number.
>Please note that this process may produce a negative number. If that happens,
>simply add 11 to make it positive again.


I just ran into a two-page description of the "real" MOD-11
checkdigit calculation.

If there is any interest I could type it in for ya'll.

I could even modify my UPC-A & CreditCard checkdigit routine to
handle MOD-11 and post that too.


Sheila B. Parker

unread,
Feb 25, 1995, 11:12:10 PM2/25/95
to
David K. Bryant (dbr...@netcom.com) wrote:
: I just ran into a two-page description of the "real" MOD-11
: checkdigit calculation.

: If there is any interest I could type it in for ya'll.

: I could even modify my UPC-A & CreditCard checkdigit routine to
: handle MOD-11 and post that too.

I'd love to see it.

Thanks,
Douglas Parker

David K. Bryant

unread,
Feb 26, 1995, 2:54:43 AM2/26/95
to
dbr...@netcom.com (David K. Bryant) writes:

There have been some recent inquiries into the subject of
the MOD-11 check digit algorithm. While browsing the local
paper-based library I found the following description of
MOD-11.

David Bryant dbr...@netcom.com

------------------------------------------------------------------------

Design of Compter Data Files 2nd Ed.
by Owen Hanson, Director of the Center for
Business Systems Analysis, The City University,
London, England.

ISBN 0-7167-8197-2 1988

US Publisher:
Computer Science Press
1803 Research Blvd
Rockville MD 20850

UK Publisher:
Pitman Books Ltd
128 Long Acre
London WC2E 9AN Great Britain

------------------------------------------------------------------------

Chapter 10 - Accuracy, integrity, and security

(f) Check digit usage

Most errors in numeric fields are due to:

1. Transcription, in which the wrong digit is written

1234 entered as 1237

2. Transposition, in which tow digits swap places

1234 entered as 1324

3. Double transposition, in which two digits that are not
adjacent swap places

1234 entered as 4231

4. Random, in which a selection of the above errors occurs

1234 entered as 0214, 3914, or 2124

All of the first three types of error can be detected by adding
an appropriate check digit. The objective of a check digit is
to provide extensive self-checking facilities in the number.
This it does by weighting each position of the original number
differently and using a prime number modulus for calculation,
so that changes in position of two digits will be detected.
If larger number of digits are in error the sum of the changes
in weighting may add up to the modulus, which would make the
error undetectable. The method operates as follows:

Take a number, say 1234. Multiply each digit, starting from
the right, by 2, 3, 4, ... 11, 2, 3, 4, ...:

1 2 3 4
x5 x4 x3 x2
=== === === ===
5 8 9 8

Add these sums:

5 + 8 + 9 + 8 = 30

Divide by 11 to give 2, remainder 8.

Subtract 8 from the modulus (11) to give the number required to
make up the sum to a multiple of the modulus:

11 - 8 = 3

This provides a check digit of 3.

The full number is now stored as 12343. The sum of

(1x5) + (2x4) + (3x3) + (4x2) + (3x1) = 33

which is divisible by 11. The number is therefore assumed to be
valid, as there is no remainder when it is divided by the modulus.

All single- or double-digit errors will be detected so long as the
modulus is a prime and larger than the number of digits in the
number being checked. This is because the error introduced will
be the product of the difference between the numbers and the
difference between their positions (their weights). This cannot
be the modulus or a multiple of it because neither of the terms
making up the produce is as large as the modulus, which is a
prime. Thus, using our earlier examples of errors, and assuming
that in each case the number was intended to be 1234 with a
check digit of 3, we will obtain:

12373 gives

(1x5) + (2x4) + (3x3) + (7x2) + (3x1) = 39

13243 gives

(1x5) + (3x4) + (2x3) + (4x2) + (3x1) = 34

42313 gives

(4x5) + (2x4) + (3x3) + (1x2) + (3x1) = 42

21243 gives

(2x5) + (1x4) + (2x3) + (4x2) + (3x1) = 31

None of these is divisible by 11, and so each is immediately shown
to be in error. However, the other two "random" errors lead to a
different result:

02143 gives

(0x5) + (2x4) + (1x3) + (4x2) + (3x1) = 22

39143 gives

(3x5) + (9x4) + (1x3) + (4x2) + (3x1) = 55

Both of these would appear to be correct; they were deliberately
intended to seen so. With modulus n, it must be expected that
there will be a probability of 1/n that random errors will lead
to numbers that appear to be correct. Thus the effectiveness of
check digits will depend on the rate of occurence of random errors
and the size of the modulus. IBM (3) claims a 97 per cent detection
rate for transposition and transcription errors using modulus 11
checking. Daniels and Yeates (4) predict 100 per cent detection
for these errors and 90.9 per cent for random errors. They quote
a case in which only five errors were undetected out of 1000
actual errors (this figure itself was 1 per cent of the total
data entries).


(3) Introduction to IBM Direct Access Storage Devices and
Organization Methods, IBM Manual No. GC20-1649, pp 11-17.

(4) Basic Training in Systems Analysis, edited by Daniels and
Yeates, Pitman, 1971, p93.


0 new messages