04.01.07

ISBN

Posted in Uncategorized at 1:46 pm by Twm

I was never really good at abstract maths at school. I tended to appreciate maths with real world usage in order to provide an ecological setting to the problem. However, I was gripped by number theory and the historical characters who were attracted to numbers for the sake of numbers.
Having studied Number theory in university, I’m frequently disappointed by yet another field that I’ve not used in my current career and seem to be forgetting how to do it. I was sitting on a train, staring at the back cover of a book having completed it. I noticed the ISBN and remembered how we were taught the code as part of our cryptography course at UNI. Disappointed that I’d forgotten how to calculate a valid ISBN, I thought I would re-acquaint myself.

The 10 digit ISBNs is an incredibly elegant solution to the problem of typos. It’s pretty obvious that if you go to the bother of establishing an universal book ID that a fair number of these digits will be entered into computer systems worldwide every day and so the chance of small human errors occurring is highly likely. The net waste worldwide to problems caused by incorrect input of data is incalculable but surely to blame for many “computer errors” that we frequently encounter as excuses for problems with orders.

ISBN10 is a 10 digit code, the first nine digits identify the country code, publisher ID and publication number. They are allocated in blocks to publishers. The interesting bit is digit number 10. This is a redundant check digit which is generated by applying a simple formula to the first 9 digits.

The calculation in python code:

def ISBNCheckDigit(isbn):
    multiplier = range(10,1,-1)

    sum=0

    for n in range(9):
        sum = sum+ int(isbn[n]) * multiplier[n]

     checkDigit = 11-(sum%11)
    return checkDigit

Digit number 1 is multiplied by 10, digit 2 by 9 and so forth and the whole sum is divided by 11 giving the remainder. The remainder may be 10, so it’s taken from 11 in order to yield a single check digit.

The clever thing about the code is that is is guaranteed to spot transpositional errors. That is where two digits have been swapped – a common typo.

The detection of a transpositional error relies on 11 being a prime number. When you transpose two numbers, you get a different value for each multiple. Since none of these are divisors of 11, you can be sure that the sum will be unique when two digits are transposed (unless they are the same digit).
Link to code