Projects‎ > ‎


Hamming Code in Python

Due: Mon Sep 14 2015 at 11:59pm in your Github repo for project1 (I will provide the repo).

This is a Python warm up project. You are going to implement a Hamming Code encoder, decoder, error finder, and error corrector in Python.

See this page for details on the Hamming Code calculation:

You should write a Python program called hamming that accepts the following command line arguments:

$ python <type> <command> <arg1> <arg2>

Where <type> is one of:
  • asc - ASCII encoding
  • bin - Binary encoding
Where <command> is one of:
  • enc <infile> <outfile>
    • Encode
  • dec  <infile> <outfile>
    • Decode
  • chk <infile>
    • Check
  • fix <infile> <outfile>
    • Fix
  • err <pos> <infile> <outfile>
    • Create an error at bit postion <pos>
For example,

$ python asc enc hello.txt hello.asc

Will encode the ASCII file into a hamming code version of the file in which each character is a '0' or a '1'. You can assume you will encode 8 bit values.

Using the ASCII encoding keeps things simple while you are developing your hamming code algorithm.

The Binary encoding is more compact as the resulting encoded file will be binary data instead of ASCII data. However, you will need to use bitwise operators to build up your result file.

You should structure your program using Python classes in order to reuse as much code as possible. Also try to use as much functional style programming as possible. See:

You can break down your program into multiple files.

You will need to write test code for your solution.


  • The Python source for the hamming encoder
  • A README that describes your design
  • Test code that verifies the correctness of your code:
    • I should be able to look the test code and understand it
    • I should be able to run all the tests from the command line
    • There should be output that indicates the tests pass
  • Your solution should be submitted in your Github repo (I will provide the repo)

Greg Benson,
Sep 3, 2015, 6:28 PM
Greg Benson,
Sep 3, 2015, 6:28 PM
Greg Benson,
Sep 3, 2015, 6:28 PM
Greg Benson,
Sep 17, 2015, 5:59 PM