LockerGnomeTech news and nostalgia for today's technology professionals
Subscribe

Search

RetroLuhn algorithmIBMpatents

The last digit of your card number is a check digit from Hans Peter Luhn's 1954 hand-held mechanical computer

IBM's Luhn built it to catch invoice typos, with belts, slots and a stylus. The same arithmetic is still running on card numbers, and one swapped pair slips straight past it.

Chris Pirillo, drawn as a 1950s patent figure, slides a stylus down a slotted hand-held calculating plate.
Illustration: LockerGnome

The patent is titled “Computer for verifying numbers,” and its first substantive sentence says what it is: “a hand computer for computing a check digit for numbers.” Luhn, of Armonk, New York, filed it for IBM on January 6, 1954. It was granted on August 23, 1960.

The problem is in the patent’s background. Many parts are “ordered, manufactured, invoiced, shipped, and billed” by long numbers, and every time somebody copies one, “it often happens that an error occurs by transposing two of the digits.” Two digits swap, the part number now names a different part, and the invoice goes out for the wrong thing.

The obvious fix is to add the digits and keep the total, a check digit. It fails on exactly the mistake Luhn was after. Add 1 and 8 and you get 9, and add 8 and 1 and you get the same 9. Transposition doesn’t change a plain sum.

So he changes what gets added. Every other digit is replaced by a substitute, “twice the original digit plus an end around carry.” Double the digit, and if the result has two digits, add them together: 6 becomes 12, which becomes 1 plus 2, which is 3. Now position matters. In the patent’s example, 4872148 comes out to a running total of 6, and the check digit to append is the total’s tens complement, which the patent words as “the check digit to be appended is derived by adding to this sum its tens complement.” Here that is 4, so the number becomes 48721484. Run the same process on that number and a result of 0 means it checks out. Anything else, and a digit was miscopied.

Try the swap. Put 1 and 8 in the doubled position and the plain one: 1 doubles to 2, and 2 plus 8 is 10. Swap them: 8 doubles to 16, which is 1 plus 6 for 7, and 7 plus 1 is 8. Ten and eight don’t match, so the check fails and someone looks at the invoice.

The patent’s device does this with no electricity. The casing has a column of parallel slots down the front, and you put “a pencil or stylus” into aligned apertures and drag it down, one slot per digit. Inside are “a plurality of narrow endless belts,” a wider belt behind them, a “digit wheel 27” and a window where the check digit shows. A reset knob on the side returns everything to zero. The stated aim is “a simple, inexpensive and portable computer.” It is a pocket abacus with a doctorate in invoicing.

The same arithmetic is still at work. According to Wikipedia’s Luhn algorithm entry, the formula is specified in ISO/IEC 7812-1, the standard for payment card numbers, and the 15-digit IMEI that identifies a phone ends in a Luhn check digit too. The last digit of your card number checks out because a patent examiner approved a slotted box 66 years ago.

Luhn’s trick is worth stealing even if you never build a belt-driven computer. Check digits are the cheapest data-quality tool there is: one extra character, a few lines of arithmetic, and a whole class of human errors gets caught at the point of entry, not three systems downstream. Any ID your own system hands out and people retype later, such as order numbers or ticket codes, can carry one.

The design choice to watch is what the digit is asked to catch. Luhn picked the mistake clerks make most, the swapped pair, and built the whole scheme around it. A check built for typos won’t catch fraud, and nothing in the patent claims otherwise.

Swap a 0 and a 9, and the 1954 gadget still can’t tell.

More Retro

Every Retro story →