getMethod('getGeneratorPolynomial'); $getGeneratorMethod->setAccessible(true); $generator = $getGeneratorMethod->invoke($rs, $ecCodewords); echo "Generator polynomial: " . implode(', ', $generator) . "\n"; echo "Note: First coefficient is 0, which is unusual.\n\n"; // The issue might be that we're using the generator polynomial incorrectly // In standard Reed-Solomon, the generator polynomial is monic (leading coefficient = 1) // But our stored polynomials start with 0 // Let's check if we should skip the first coefficient if ($generator[0] === 0) { echo "Generator polynomial starts with 0 - this might be the issue.\n"; echo "In standard RS, generator should be monic (leading coefficient = 1).\n\n"; // Try without the first coefficient $generatorWithoutZero = array_slice($generator, 1); echo "Generator without leading 0: " . implode(', ', $generatorWithoutZero) . "\n"; echo "This would be a monic polynomial of degree " . (count($generatorWithoutZero) - 1) . "\n\n"; } // Test the actual encoding $ec = $rs->encode($data, $ecCodewords); echo "EC codewords: " . implode(', ', $ec) . "\n\n"; // Now let's verify with our decoder require_once __DIR__ . '/test-reed-solomon-decoder.php'; $fullCodeword = array_merge($data, $ec); $decoder = new SimpleRSDecoder(); $syndromes = $decoder->calculateSyndromes($fullCodeword, $ecCodewords); echo "Syndromes: " . implode(', ', $syndromes) . "\n"; $allZero = true; foreach ($syndromes as $s) { if ($s !== 0) { $allZero = false; break; } } if ($allZero) { echo "✅ All syndromes are zero - codeword is valid!\n"; } else { echo "❌ Syndromes are not all zero - codeword is invalid!\n"; echo "\nThe problem is in the polynomial division algorithm.\n"; }