Charlie ([info]vruba) wrote,
@ 2008-04-12 02:03:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Current music:Orbital: The Box

ISO 6346 check digit error hunt

I was looking at a freight container the other day and it occurred to me to hope that the number on it was what it turned out to be: a tracking mark under an international standard with a single namespace. Well! That’s a bed for some planetwide infrastructure nerdery. There are plenty of people taking down plane, train, ship, and currency numbers (sometimes discovering things of wider interest), and here’s another set of things with that seductive property of being the most widespread, often-moved, and recognizable objects their size in human space. When people start tracking them (possibly via OCR of trainyards), I’m in.

But first there’s something else intriguing, and it involves me buying you coffee. ISO 6346 marks, as general tracking numbers ought to be, are checksummed.

— All right, hang on. This is where I normally say “if you don’t know what a checksum is and aren’t already Wikipeding or Googling it, you’re incurious and dull”. But I don’t really like what Wikioogle has to say to the lay person. So we can discuss them in some depth later, but for now what you should know is that checksums are small numbers derived from bigger numbers that reassure you that the bigger number arrived free of errors.

Anyway, quite reasonably, ISO 6346’s precaution against error is a check digit: a single numeral. Now, I don’t know a lot about checksum practice, but I thought it was usual to pick a function with an output in your chosen alphabet (the Luhn algorithm for the decimal digits on credit cards) or an alphabet that covers your chosen function (0–9 plus X for the ISBN check’s 11 possible outputs). However, the ISO 6346 check has a range of 0–10 represented by the numerals 0–9. Conceptually, the space that would be used by 0/10 is spent on making sure every single-digit error changes the checksum. So they recommend that you not assign numbers that check to 10.

In celebration of this, the most byzantine and debatable piece of standardscraft I’ve seen all month, I introduce the following challenge:

  1. I will buy a coffee or equivalent for the first person to post here with a non-doctored photograph of themselves or a close associate pointing, preferably while wearing a humorous expression, at a freight container with an ISO 6346 mark with a checksum of 0 representing 10.
  2. Another coffeequivalent for ditto but any other checksum error.
  3. A third for anyone who wins either of the first two by buying a freight container.

For your convenience, some checksum code (thanks for the highlighting, SubEthaEdit!):

#!/usr/bin/env python # Calculate an ISO 6346 check digit (probably). # The official algorithm costs about $100 to know. # 2008-04-11 by Charlie Loyd. from re import compile as regex from string import uppercase def iso6346checksum(code, ten='error'):   '''Call with a string like 'TEXU 328422' and optionally ten=   what you want a check digit of 10 to return instead of an error   (probably 0 or 10)'''   valid = regex('[A-Z]{3}[UJZ] [0-9]{6}')   if not valid.match(code):     raise ValueError, code + ' should look like "ZZZZ 111111".'      prefix, suffix = code.split()   prefix = list(prefix)   # Letter values are A=10, etc., skipping those divisible by 11, so Z=38   lettervals = filter(lambda e: e % 11 != 0, range(10, 39))   lettertable = dict(zip(uppercase, lettervals))   prefix = [lettertable[l] for l in prefix]      code = prefix + map(int, list(suffix))   s = sum([code[ind] * 2**ind for ind in range(0, 10)])      dummy = int(s/11) * 11 # futureproof!   cksum = s - dummy   if cksum == 10:     if ten == 'error':       raise ValueError, 'ISO 6346 checksum of 10.'     else: return ten   else: return cksum



(3 comments) - (Post a new comment)


[info]saromia
2008-04-12 10:27 pm UTC (link)

(Reply to this) (Thread)


[info]vruba
2008-04-12 10:31 pm UTC (link)
Cheep cheep cheep cheep cheep cheep eep cheep cheep. Cheep cheep cheep cheep cheep cheep cheep peep peep cheep cheep cheep. Cheep cheep cheep cheep cheep. Cheep eep eep, cheep cheep cheep cheep cheep cheep cheep. Cheep cheep. Cheep cheep cheep cheep.

(Reply to this) (Parent)

CPIU8126750
(Anonymous)
2008-05-26 12:40 pm UTC (link)
Last friday I made pictures of our containers. Didn't read this post yet, so I'm not pointing, while wearing a humorous expression, at our freight containers ;)

But it is a checksum representing 10: CPIU8126750

Image


More pictures:

pic1 (http://www.fizzl.com/temp/pic1.jpg)
pic2 (http://www.fizzl.com/temp/pic2.jpg)
pic3 (http://www.fizzl.com/temp/pic3.jpg)
pic4 (http://www.fizzl.com/temp/pic4.jpg)


-- Joep

(Reply to this)


(3 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…