Reed-Solomon codewords are the remainder when your message polynomial is divided by the generator. Today you write that division - the synthetic long-division loop over GF(256) - and read back the remainder.
Divide a message polynomial by a monic divisor and return the remainder coefficients.
Dividing polynomials over GF(256) is the same synthetic division you learned in school, with XOR standing in for subtraction. Walk the dividend from its highest-degree coefficient. At each position the current coefficient tells you how much of the divisor to cancel there: multiply the whole divisor by that coefficient and XOR it into the working array, which zeroes the leading term and folds the rest downward. Because the generator is monic - its leading coefficient is 1 - you never have to divide to find the multiple; the leading coefficient is the multiple.
You pad the message with as many trailing zeros as there are error-correction codewords, so the remainder has somewhere to accumulate. After the loop, the low len(div)-1 coefficients are the remainder - here [4, 4]. That remainder is precisely the Reed-Solomon error-correction data; the next lesson wraps this division into the encoder and runs it on the real HELLO WORLD block.
// Work on a copy. For each of the leading positions, use that// coefficient to cancel the divisor beneath it (XOR). The tail// that is left, as wide as the remainder, is the answer.func polyRem(msg, div []byte) []byte {r := append([]byte(nil), msg...)for i := 0; i <= len(msg)-len(div); i++ {c := r[i]if c != 0 {for j := range div {r[i+j] ^= gmul(div[j], c)}}}return r[len(msg)-(len(div)-1):]}