pyatl/jam-sessions

Challenge Submission - Baudot Code Encoder/Decoder

Closed this issue · 3 comments

Synopsis

Back in the days of Teletypes, the Baudot code was the standard protocol for most telecommunications. It was patented in 1870 by the French engineer Émile Baudot, and was later modified by the New-Zealander engineer Donald Murray. This later code remained in use through most of the first half of the XXth century.

For more information, see https://en.wikipedia.org/wiki/Baudot_code

Examples

The Baudot code is a 5-bit binary code, usually represented on a ribbon of punched tape.
You'll notice that such a code has only 32 possible combinations, which wouldn't be enough for the 26 letters and the ten digits… The trick is that the code has actually multiple tables, with special control characters to switch between each mode. To put it simply, to read the code you need to know at any time whether you're in "Letter mode" or "Symbol mode", and have to switch from one to another when needed.

In this exercise, you will be implementing a decoder for the ITA2 US variant. The full table is on the next page.

The code will need to be a function that:
Takes in a string that looks like tape. There will be one code per line. That code uses underscore (_) for 0 and star (*) for 1
returns a plain text string

As a bonus, you can make an encoder for the code as well!

Code   Letter mode  Figure mode
_____  Null (\x00)  Null (\x00)
___*_  CR (\r)      CR (\r)
_*___  NL (\n)      NL (\n)
__*__  Space        Space
***_*  Q            1
**__*  W            2
*____  E            3
_*_*_  R            4
____*  T            5
*_*_*  Y            6
***__  U            7
_**__  I            8
___**  O            9
_**_*  P            0
**___  A            -
*_*__  S            Bell (\x07)
*__*_  D            $
*_**_  F            !
_*_**  G            &
__*_*  H            #
**_*_  J            '
****_  K            (
_*__*  L            )
*___*  Z            "
*_***  X            /
_***_  C            :
_****  V            ;
*__**  B            ?
__**_  N            ,
__***  M            .
**_**  Figures      Figures
*****  Letters      Letters

Example test in Python:

input_hw = """
*****
__*_*
*____
_*__*
_*__*
___**
__*__
**__*
___**
_*_*_
_*__*
*__*_
**_**
*_**_
"""

def test_hello_world():
    assert baudot_decode(input_hw) == "HELLO WORLD!"

Submitted by Xavier

Approved for April 2019 Jam Session