I'm trying to implement a BCH 18,6 decoder for QR Code version verification, and am having a hard time with syndrome calculation. My understanding is that the syndromes should be 0 when the codeword has no errors, but that's not what I'm getting.
The generator polynomial used to encode the version is, per the QR Code spec ISO/IEC 18004:2000(E) (Annex D) is:
$G(x) = x^{12} + x^{11} + x^{10} + x^9 + x^8 + x^5 + x^2 + 1$
The example used in that annex is:
- Data (version): 000111
- Error correction: 110010010100
- Codeword: 000111110010010100
Which gives me
$R(x) = x^{14}+x^{13}+x^{12}+x^{11}+x^{10}+x^7+x^4+x^2$
The spec says to calculate syndrome $S_i$ (for i=1,3,5) by evaluating $R(\alpha^i)$. So i'm trying $S_1$, which gives me:
$S_1 = \alpha^{14}+\alpha^{13}+\alpha^{12}+\alpha^{11}+\alpha^{10}+\alpha^7+\alpha^4+\alpha^2$
I then simplify the terms $\alpha_i$ (for $i>4$) by replacing them with their $GF(2^5)$ equivalents. The spec didn't tell me which $P(x)$ to use, so I picked $P(x)=x^5+x^2+1$ from here. Later I tried all the irreducible degree 5 polynomials from this answer, with no better luck. I suspect that's supposed to be unsurprising, but I'm not sure why. Anyway, back to using $P(x)=x^5+x^2+1$.
To get the in-$GF(2^5)$ values, I started with $\alpha^4=10000$. To calculate $\alpha^5$, left shift 1, then because MSB is 1, XOR with $100101$, get $\alpha^5 = 00101$, and so on for $\alpha^i$ for every i through 14. Thus $\alpha^{14}=11101$, so $\alpha^{14}=\alpha^4+\alpha^3+\alpha^2+1$. Apply that to all terms, and we get:
$S_1 = (\alpha^4+\alpha^3+\alpha^2+1) + (\alpha^4+\alpha^3+\alpha^2) + (\alpha^3+\alpha^2+\alpha) + (\alpha^2+\alpha+1) + (\alpha^4+1) + (\alpha^4+\alpha^2) + \alpha^4 + \alpha^2$
which is:
$S_1 = \alpha^4+\alpha^3+1$
which isn't zero. What am I doing wrong? This same algorithm works for BCH(15,5), which makes me think there's some subtlety of BCH(18,6) or $GF(2^5)$ that I'm missing.