getMethod('getGeneratorPolynomial'); $getGeneratorMethod->setAccessible(true); $generator = $getGeneratorMethod->invoke($rs, 10); echo "Generator polynomial: " . implode(', ', $generator) . "\n"; echo "Note: This represents g(x) = (x-α^0)(x-α^1)...(x-α^9)\n\n"; // The generator roots are α^0, α^1, ..., α^9 // For a valid codeword, c(α^i) should be 0 for i = 0 to 9 $fullCodeword = array_merge($data, $ec); echo "Full codeword: " . implode(', ', $fullCodeword) . "\n\n"; // Test: Evaluate codeword polynomial at generator roots echo "=== Evaluating at Generator Roots ===\n"; echo "For a valid RS codeword, c(α^i) should be 0 for all generator roots.\n\n"; // Standard RS: c(x) = c[0] + c[1]*x + c[2]*x^2 + ... + c[n-1]*x^(n-1) // But QR codes might use different polynomial representation // Test 1: Standard polynomial (LSB-first) echo "Test 1: Standard polynomial c(x) = c[0] + c[1]*x + ...\n"; $syndromes1 = []; for ($i = 0; $i < 10; $i++) { $alphaPower = $gfExp[$i]; $syndrome = 0; $power = 1; // x^0 = 1 for ($j = 0; $j < count($fullCodeword); $j++) { $syndrome ^= gfMult($gfExp, $gfLog, $fullCodeword[$j], $power); $power = gfMult($gfExp, $gfLog, $power, $alphaPower); } $syndromes1[$i] = $syndrome; echo " c(α^{$i}) = {$syndrome}\n"; } $allZero1 = array_sum($syndromes1) === 0; echo ($allZero1 ? "✅" : "❌") . " All syndromes are zero\n\n"; // Test 2: Reversed polynomial (MSB-first) // c(x) = c[0]*x^(n-1) + c[1]*x^(n-2) + ... + c[n-1] echo "Test 2: Reversed polynomial c(x) = c[0]*x^(n-1) + c[1]*x^(n-2) + ...\n"; $n = count($fullCodeword); $syndromes2 = []; for ($i = 0; $i < 10; $i++) { $alphaPower = $gfExp[$i]; $syndrome = 0; // Start with x^(n-1) evaluated at α^i $power = $gfExp[($i * ($n - 1)) % 255]; for ($j = 0; $j < $n; $j++) { $syndrome ^= gfMult($gfExp, $gfLog, $fullCodeword[$j], $power); // Divide by α^i (multiply by α^(255-i)) $power = gfMult($gfExp, $gfLog, $power, $gfExp[255 - $i]); } $syndromes2[$i] = $syndrome; echo " c(α^{$i}) = {$syndrome}\n"; } $allZero2 = array_sum($syndromes2) === 0; echo ($allZero2 ? "✅" : "❌") . " All syndromes are zero\n\n"; // Test 3: Maybe we need to evaluate at different roots? // Generator: g(x) = (x-α^0)(x-α^1)...(x-α^9) // But maybe the roots are α^1, α^2, ..., α^10? echo "Test 3: Evaluating at α^1 to α^10 (shifted roots)\n"; $syndromes3 = []; for ($i = 1; $i <= 10; $i++) { $alphaPower = $gfExp[$i]; $syndrome = 0; $power = 1; for ($j = 0; $j < count($fullCodeword); $j++) { $syndrome ^= gfMult($gfExp, $gfLog, $fullCodeword[$j], $power); $power = gfMult($gfExp, $gfLog, $power, $alphaPower); } $syndromes3[$i - 1] = $syndrome; echo " c(α^{$i}) = {$syndrome}\n"; } $allZero3 = array_sum($syndromes3) === 0; echo ($allZero3 ? "✅" : "❌") . " All syndromes are zero\n\n"; if ($allZero1 || $allZero2 || $allZero3) { echo "✅ Found correct evaluation method!\n"; } else { echo "❌ None of the methods work. The problem might be in the generator polynomial.\n"; }