Baudot fun

This is a throwaway piece of code, so it’s probably buggy but what the heck!

# -*- coding: utf-8 -*-
import sys

zero = '○'
one = '●'

numbers = []

def int2bin(n, count=5):
    """returns the binary of integer n, using count number of digits"""
    return "".join([ zero if ((n >> y) & 1) == 0 else one for y in range(count-1, -1, -1)])

def write(code):
    print numbers

def output(newstate, curstate, code):

    figs = 27
    ltrs = 31

    if newstate == 0 and curstate == 1:
    elif newstate == 1 and curstate == 0:


    return newstate

def translate(input):
    global numbers

    numbers = map(int2bin,range(0,32))
    baudot_letters = '@E@A SIU@DRJNFCKTZLWHYPQOBG@MXV@'
    baudot_symbols = '@3@- @87@$4\',!:(5")2@6019?&@./;@'

    cr = 8
    lf = 2
    sp = 4
    state = 0

    for c in input.upper():
        if c == '@':
        if c == ' ':
        elif c == '\n':
            ix = baudot_letters.find(c)
            if ix != -1:
                state = output(0, state, ix)
                ix = baudot_symbols.find(c)
                if ix != -1:
                    state = output(1, state, ix)

if __name__ == '__main__':
    for arg in sys.argv[1:]:

In case you're wondering, the Baudot code was invented in 1870 by Émile Baudot and later became the foundation of the international telex alphabets. See

The original telex machines were electro-mechanical beasts which used this 5-bit code for wire transmission. Telex machines could encode text to punched tape for later sending. They could also print incoming telex transmissions to tape as well as paper. I remember seeing in a post bureau in Pakistan a journalist receiving a message on one telex machine and feeding the output spool of tape into another as it arrived. An early version of message forwarding!

Example output of the above:

johncc@liberator:~$ python 'Hello world!'


0 Responses to “Baudot fun”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Top artists this week from

My Twitter feed


%d bloggers like this: