getMethod('getGeneratorPolynomial'); $getGeneratorMethod->setAccessible(true); $stored = $getGeneratorMethod->invoke($rs, 10); echo "Stored generator polynomial (10 EC codewords):\n"; echo " [" . implode(', ', $stored) . "]\n"; echo " Length: " . count($stored) . " (expected: 11)\n"; echo " First coefficient: {$stored[0]}\n\n"; // The stored polynomial starts with 0, which is unusual // In standard RS, generator should be monic (leading coefficient = 1) // But maybe the stored format is different // Try generating it dynamically $generateMethod = $reflection->getMethod('generateGeneratorPolynomial'); $generateMethod->setAccessible(true); $generated = $generateMethod->invoke($rs, 10); echo "Dynamically generated:\n"; echo " [" . implode(', ', $generated) . "]\n"; echo " Length: " . count($generated) . " (expected: 11)\n"; echo " First coefficient: {$generated[0]}\n\n"; // The generated one starts with 1 (monic), which is correct // But the stored one starts with 0 // Maybe we need to prepend 0 to the generated one, or remove the first 0 from stored echo "=== Hypothesis ===\n"; echo "The stored polynomials might be in a different format.\n"; echo "Maybe we need to:\n"; echo " 1. Use stored polynomials as-is but skip first coefficient?\n"; echo " 2. Or convert stored [0, a, b, ...] to [1, a, b, ...]?\n"; echo " 3. Or use generated polynomials instead of stored ones?\n\n"; // Test: What if we use the generated polynomial instead? echo "=== Test: Using Generated Polynomial ===\n"; // Modify the encode method to use generated polynomial // But first, let's check if the stored polynomial is actually correct // by comparing with known QR code specification values $expected = [0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45]; echo "Expected from specification:\n"; echo " [" . implode(', ', $expected) . "]\n\n"; if ($stored === $expected) { echo "✅ Stored polynomial matches specification!\n"; echo "\nSo the stored format [0, ...] is correct.\n"; echo "The problem must be in how we use it in the division algorithm.\n"; } else { echo "❌ Stored polynomial doesn't match specification!\n"; }