Re: Barcode Vocalization Application

From: Jan Karrman <jan_at_it_dot_uu_dot_se>
Date: Mon Oct 06 2003 - 12:30:41 CDT

On Mon, 6 Oct 2003, Skip Montanaro wrote:

> Further to that point, if written in Python, others (like myself) who were
> solicited in comp.lang.python could assist. I have little enough time as it
> is (witness the lack of progress on the website - I'm still offline except
> for time spent at my day job). I'm not going to spend time learning the
> dBase scripting language or locating and installing tools to use it.
>
> (Maybe there's someone who knows both who can translate?)
>

See below.

Due to a rainy and gloomy weekend here in Sweden, I managed to do
quite a bit of coding. The paper ballot function is more or less
finished, and I have also written a votes2digits() function. I will
upload the files once I have polished them, and added some comments.

But you can test them right now! I realized that I had to make some
tool so I could easily test many cases. So I made this HTML form:

  http://user.it.uu.se/~jan/voting-project/ballot.html

This is *not* an attempt to make the HTML version of the ballot for
the demo - it is merely for test purposes. There are several ways
to make invalid votes (for example more than three votes for Cat
Catcher), and in some cases you may get an "Internal Server Error".
I have not noticed any problems with valid votes, though; but as
usual, bugs are often revealed when others start using a tool. So I
would appreciate if you could make some tests, and see if it works.

At the bottom of the page you can select "Print ballot" and push
"Submit". The (letter sized) paper ballot should then be returned
as a PDF file. If you are equipped with a bar code scanner, you
can print the ballot and scan the code. Otherwise, select "Get bar
code number" on the form to get the code. You can then copy this
into Alan's bva application. (If you happen to have ranked Steve
Wozniak sixth in the County Commissioner race, you will hear "Steve
Wozniak ranked seventh" - but that is probably just because Alan
got bored and lost concentration while recording ;-)

Note that you can fill in the ballot number on the form. This is
if one wants to compare how the bar code obfuscation works for
identical or similar votes, with similar ballot numbers. If left
out, a random four digit number will be generated.

I have a dual boot laptop at home with Linux (Redhat) and Win2000.
Since I develop under Linux, it became messy to reboot each time I
wanted to run my tests with Alan's application (I failed to compile
it on Linux with the Harbour tool). So I wrote a playing script in
Python, included below. It uses the "play" command, installed by
default on Redhat 9. Of course, the script can easily be modified to
call some other audio player. You need to edit the last line of the
script to reflect the directory where you have unpacked Alan's audio
files. There is no graphical interface, just call the script from the
command line with the bar code number as parameter.

/Jan

import os, sys, string

def tobinary(dec):
    bin = []
    while dec > 0:
        bit = int(dec % 2)
        bin.insert(0, bit)
        dec = (dec - bit)/2
    return bin

def revert(key, num):

    keydigits = list(key)
    numdigits = list(num)
    for i in range(len(numdigits)):
        numdigits[i] = str((int(numdigits[i]) - int(keydigits[i % 4])) % 10)
    return string.join(numdigits, "")

def Play(digits, bvadir):
    bits = tobinary(long(revert(digits[:4], digits[4:])))
    for i in range(116-len(bits)):
        bits.insert(0, 0)
    length = [8, 8, 3, 3, 4, 3, 4, 3, 2, 2, 2, 10, 64]
    n = 1
    offset = 0
    wav = []
    commiss = [""] * 8
    for i in range(len(length)):
        contest = bits[offset:offset+length[i]]
        casted = 0
        for j in contest:
            if j == 1:
                casted = 1
        if casted == 1:
            for j in contest:
                if j == 1:
                    if n < 53:
                        wav += ["SEL%.3d.WAV" % n]
                    else:
                        commiss[(n-53)%8] = "SEL%.3d.WAV" % n
                n += 1
        else:
            wav += ["NP%.2d.WAV" % (i+1)]
            n += length[i]
        offset += length[i]
    wav += commiss
    for file in wav:
        if file != "":
            os.system("play %s/%s" % (bvadir, file))

Play(sys.argv[1], "/home/jan/voting-project/bva")
==================================================================
= The content of this message, with the exception of any external
= quotations under fair use, are released to the Public Domain
==================================================================
Received on Fri Oct 31 23:17:01 2003

This archive was generated by hypermail 2.1.8 : Fri Oct 31 2003 - 23:17:06 CST