'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe;
All mimsy were the borogoves,
And the mome raths outgrabe.
--Lewis Carroll
Part 1
Write programs that perform the following mappings on bits/bytes:
- atob:
This takes as input a text file and outputs a text file of bits where each ASCII character in
the input file is replaced by the sequence of bits which represents its ASCII code.
Each bit is represented by either the character '0' or the character '1'.
- btoa:
This takes as input a text file of bits (where each bit is given by either the character '0' or
the character '1') and outputs a sequence of ASCII characters. Here, each sequence of 8 bits is
converted to a single ASCII character. The number of bits in the input file is a multiple of 8.
Here are some sample runs of these transformations:
$ ./atob wright.txt bit-wright.txt
$ ./btoa bit-wright.txt ascii-wright.txt
and the files:
wright.txt, bit-wright.txt,
ascii-wright.txt.
Remark: The first and third files should be identical.
Part 2
Also write programs that carry out the following pair of morphisms on bit sequences.
This bit-to-bit transformation will be explained in class.
- jabber:
This takes as input a text file of bits (where each bit is given by either the character '0' or
the character '1') and outputs a text file of bits.
- wocky:
This takes as input a text file of bits (where each bit is given by either the character '0' or
the character '1') and outputs a text file of bits.
This transformation will undo jabber.
Here are some sample runs of these transformations:
$ ./jabber bit-wright.txt zap-wright.txt
$ ./wocky zap-wright.txt kapow-wright.txt
and the files:
bit-wright.txt, zap-wright.txt,
kapow-wright.txt.
Remark: The first and third files should be identical (in their bit sequences).
We now combine both pairs of transformations by composing "atob" and "jabber" on one side,
and "wocky" and "btoa" on the other side. Since "atob" and "btoa" are inverses of each other,
and "jabber" is the inverse of "wocky", we should get the do-nothing (identity) transformation.
Sample file
Here is T.S. Eliot's "Hollow Men".
Some testing the program on the above poem.
$ ./atob hollow.txt bit-hollow.txt
$ ./jabber bit-hollow.txt zap-hollow.txt
$ ./wocky zap-hollow.txt kapow-hollow.txt
$ ./btoa kapow-hollow.txt out.txt
$ diff hollow.txt out.txt
Here are some output files:
bit-hollow.txt,
zap-hollow.txt,
kapow-hollow.txt,
and
out.txt.