Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-300

CRC Encode Message

Problem

Compute a systematic CRC codeword from data bits and a generator polynomial given as bits, most significant first. Append len(poly) - 1 zero bits, perform binary polynomial long division by XOR-ing the generator at every leading 1, and return the data bits followed by the final remainder. Assume poly starts with 1.

Hint

Only iterate over the data positions; the remaining bits after the loop are the remainder.

Test cases

case 1
in: [[1,1,0,1],[1,0,1,1]]
expected: [1,1,0,1,0,0,1]
case 2
in: [[1,0,1],[1,1,0]]
expected: [1,0,1,0,0]
case 3
in: [[1,1,1,1],[1,0,0,1,1]]
expected: [1,1,1,1,0,0,1,0]
case 4
in: [[0,1,0,1,1],[1,0,0,1]]
expected: [0,1,0,1,1,0,1,0]
Starter codePython
def crc_encode(data, poly):
    # Your code here
    pass

4 test cases · run your code against them in the editor