# 02 - Hamming Codes (Implementation)

The preliminary requirements for this assignment:

- Git installed (see Dev > Git),
- Python installed (see Dev > Python) and worked through tutorials,
- The template forked (see Dev > template),
- The first assignment handed in (see Assignment 1 - Hamming Codes (Theory)).

In this assignment you’ll have to implement a customized systematic Hamming Code `$(10, 6)$`

with additional parity bit.
The implementation has to be capable of encoding and decoding input words, detecting errors and correcting single-bit errors if they occur.
Also, the implementation has to be done in Python using the template provided in `./hamming_code.py`

.
You will implement and run the program on your computer.

**Deadline for submission: Wednesday, 22.11.2023, 23:59 // 11:59 pm (CET)Please upload your solution into your own Gitlab repository #using the prepared files#.**

## Generator matrix

Use the following non-systematic generator matrix `$G'_{6,10}$`

for your implementation:
`\[ G' = \left( \begin{matrix} 1 & 1 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 \\ 1 & 0 & 0 & 1 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 1 & 1 & 0 & 0 \\ 1 & 1 & 0 & 1 & 0 & 0 & 0 & 1 & 1 & 0 \\ 1 & 0 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 1 \\ \end{matrix} \right) \]`

## Task 1

Do not use external packages like NumPy or other for matrices and vector arithmetic!

Everything can be done with simple plain python.

Make yourself familiar with the project structure and classes, then do the following steps:

- Add above matrix
`$G'_{6,10}$`

to your class`HammingCode`

. - Bring
`$G'_{6,10}$`

into the systematic form through implementing and executing the transformation steps listed here.- Use the pre-defined method
for your implementation.**__convert_to_g()**

- Use the pre-defined method
- Derive
`$H_{4,10}$`

from the generated matrix`$G_{6,10}$`

.- Use the pre-defined method
for your implementation.**__derive_h()**

- Use the pre-defined method

## Task 2

Implement the encoder in the function * encode()* in

`./hamming_code.py`

:- Add the missing logic for encoding given input words.

Do not overwrite the existing signature of the method (tests depend on that). - Don’t forget to calculate and add the additional parity bit
`$p_{5}$`

using*even parity*. - Make sure to return the final code as a
`Tuple`

and not as a`List`

. - Test your implementation with unit-tests (see Task 4).

## Task 3

Implement the decoder in the function * decode()* in

`./hamming_code.py`

:- Add the missing logic for decoding given input words.

Do not overwrite the existing signature of the method (tests depend on that).- Calculate the additional parity bit of the encoded word using
*even parity*. - Calculate the
*syndrome vector*without including`$p_{5}$`

(separate it beforehand). - Check the
*syndrome vector*against`$H_{4,10}$`

and conclude if the encoded word had an error.- If the encoded word was without an error, return the decoded word and VALID.
- If the encoded word had a single error, return the corrected decoded word and CORRECTED.
- If the encoded word had multiple errors, return
`None`

and UNCORRECTABLE.

- Calculate the additional parity bit of the encoded word using
- Make sure to return the final code as a
`Tuple`

and not as a`List`

. - Test your implementation with unit-tests (see Task 4).

Make sure to return Enum keys only, not the value!

## Task 4

Now we are looking into unit-tests and update the file `./test_hamming_code.py`

.

- First, import the subclasses needed from
`hamming_code.py`

. - For every given test case, implement the corresponding logic.

Use asserts and pre-defined expectations (e.g. simple variable holding the value) for the checks. - Encode the following codes (you can check them in a single function):
`$(0, 1, 1, 0, 1, 1)$`

`$(0, 0, 0, 0, 0, 0)$`

`$(1, 0, 1, 1, 0, 1)$`

`$(1, 1, 1, 1, 1, 0)$`

- Decode the following codes:
`$(0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0)$`

`$(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)$`

`$(1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1)$`

`$(1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1)$`

- Analyze the output.

Does the output of*decode()*match the input of*encode()*before? - Bring up at least two more test cases (one for codes being corrected and one for an uncorrectable code).

**Do not exchange source code! Keep it private!**

We do not tolerate plagiarism.

Plagiarism of any form will get you disqualified from the lab.