[reportlab-users] Code 39 Check digit bug ?

Robin Becker robin at reportlab.com
Fri Jul 3 08:43:52 EDT 2009


Ian Cottee wrote:

> Using reportlab2.2, with python2.5 on Mac OSX

>

> from reportlab.graphics.barcode import code39

> In [2]: bc1 = code39.Extended39('48281450412')

>

> In [4]: bc1.validate()

> Out[4]: '48281450412'

>

> In [5]: bc1.encode()

> Out[5]: '*48281450412**'

>

> That check digit of '*' appears to be wrong. Our clients can't scan

> the code and the docs would appear to say that it should be a '$'.

>

> Using the code from Wikipedia at

>

> http://en.wikipedia.org/wiki/Code_39

>


I looked at the code39 _patterns and it seems that we have an extra character ie
* in between ' ' and '$'. That character is also in the _valchars array there
and in the definition of _std_chars. The _patterns are used to calculate the
value of the

Checking in the original contribution and that is there. So presumably there was
some mistake in the original coding.

I believe that * is allowed to be transmitted as the start and stop characters
(cf http://www.barcodeman.com/info/c39_1.php3) so it has a valid pattern, but
obviously there's a bug since we should not include it in the valid character set.

I have tried a small patch which is in the attached file. I've checked and we
now get the right value from _encode39 ie

>>>> code39._encode39('48281450412',1,1)

> '*48281450412$*'



can interested people try this out?




> def append_c39_checksum(st):

> charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"

> return st + charset[ sum(charset.index(c) for c in st) % 43 ]

>

> In [8]: append_c39_checksum('48281450412')

> Out[8]: '48281450412$'

>

> Is this a known issue or a misunderstanding on my part? It only

> appears to happen when the checkdigit sum is 39. We have the same

> result on the clients system which is running Ubuntu 8.04

>

> Many thanks

>

> Ian Cottee

> Blue Fountain Systems Ltd

>........


--
Robin Becker
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: code39.py
Url: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20090703/957b0dc1/attachment.ksh>


More information about the reportlab-users mailing list