encode($dataCodewords, 10); echo "EC codewords: " . implode(', ', $ecCodewords) . "\n\n"; // Create full codeword sequence $allCodewords = array_merge($dataCodewords, $ecCodewords); echo "Full codeword sequence (26): " . implode(', ', $allCodewords) . "\n\n"; // Verify: For Reed-Solomon, if we evaluate the message polynomial at the roots of the generator, // we should get zero. This is a basic sanity check. echo "=== Reed-Solomon Verification ===\n"; echo "Note: Full verification requires evaluating the polynomial at generator roots.\n"; echo "For now, we verify the structure:\n"; echo " - Generator polynomial: degree 10\n"; echo " - Data codewords: 16\n"; echo " - EC codewords: 10\n"; echo " - Total: 26 codewords\n\n"; // Test with a known working QR code library result // From qrcode.js library, for "HELLO WORLD" V1 M: // Expected EC codewords might be different echo "=== Comparison with Known Values ===\n"; echo "Note: Different QR code implementations may use different mask patterns,\n"; echo "which affects which EC codewords are generated.\n\n"; // The key test: Can we decode our own encoded data? // We need to verify that the EC codewords are correct by checking if // they can be used to reconstruct the original data echo "=== Reed-Solomon Structure Check ===\n"; echo "For RS(26, 16) with generator polynomial g(x):\n"; echo " - Message polynomial: m(x) = data + zeros\n"; echo " - Encoded: c(x) = m(x) * x^10 + (m(x) * x^10) mod g(x)\n"; echo " - EC codewords = remainder of (m(x) * x^10) / g(x)\n\n"; // Verify generator polynomial $reflection = new ReflectionClass($reedSolomon); $getGeneratorMethod = $reflection->getMethod('getGeneratorPolynomial'); $getGeneratorMethod->setAccessible(true); $generator = $getGeneratorMethod->invoke($reedSolomon, 10); echo "Generator polynomial coefficients: " . implode(', ', $generator) . "\n"; echo "Degree: " . (count($generator) - 1) . " (expected: 10)\n\n"; // Check if EC codewords match expected pattern // For RS codes, the EC codewords should have certain properties echo "EC codewords check:\n"; echo " - All EC codewords are bytes (0-255): "; $allValid = true; foreach ($ecCodewords as $ec) { if ($ec < 0 || $ec > 255) { $allValid = false; break; } } echo ($allValid ? "✅" : "❌") . "\n"; echo " - EC codeword count: " . count($ecCodewords) . " (expected: 10) "; echo (count($ecCodewords) === 10 ? "✅" : "❌") . "\n\n"; echo "If the QR code doesn't scan, the issue might be:\n"; echo "1. EC codewords are incorrect (most likely)\n"; echo "2. Data codewords are incorrect (but we can decode them, so unlikely)\n"; echo "3. Mask pattern selection is wrong\n"; echo "4. Format information is wrong (but we verified it's correct)\n";