All problems
Generator Matrix Encode
Problem
Encode a binary message by multiplying it with a generator matrix mod 2: codeword[j] = XOR over i of message[i] * G[i][j]. Return the codeword list.
Hint
Each message bit selects rows of G to XOR together.
Test cases
case 1
in: [[1,0],[[1,0,0],[0,1,1]]]
expected: [1,0,0]
case 2
in: [[0,1],[[1,0,0],[0,1,1]]]
expected: [0,1,1]
case 3
in: [[1,1],[[1,0,0],[0,1,1]]]
expected: [1,1,1]
case 4
in: [[1,0,1],[[1,0,0,1],[0,1,0,1],[0,0,1,1]]]
expected: [1,0,1,0]
Starter codePython
def generator_matrix_encode(message, g_matrix):
# Your code here
pass4 test cases · run your code against them in the editor