encode($testData1, $ec1); echo "Data: " . implode(', ', $testData1) . "\n"; echo "EC codewords: " . implode(', ', $ecCodewords1) . "\n\n"; // Test Case 2: All zeros (should produce all-zero EC) echo "Test Case 2: All zeros\n"; $testData2 = array_fill(0, 5, 0); $ecCodewords2 = $rs->encode($testData2, $ec1); echo "Data: " . implode(', ', $testData2) . "\n"; echo "EC codewords: " . implode(', ', $ecCodewords2) . "\n"; if (array_sum($ecCodewords2) === 0) { echo "✅ All-zero data produces all-zero EC (correct)\n\n"; } else { echo "❌ All-zero data should produce all-zero EC!\n\n"; } // Test Case 3: Known QR code example // From ISO/IEC 18004 specification example echo "Test Case 3: QR Code specification example\n"; // Note: This is a simplified example - actual QR codes have more complexity // Test Case 4: Verify polynomial division manually echo "Test Case 4: Manual polynomial division check\n"; // For RS(26, 16), we encode 16 data codewords with 10 EC codewords $testData4 = [64, 180, 132, 84, 196, 196, 242, 5, 116, 245, 36, 196, 64, 236, 17, 236]; $ecCodewords4 = $rs->encode($testData4, 10); echo "Data codewords (16): " . implode(', ', $testData4) . "\n"; echo "EC codewords (10): " . implode(', ', $ecCodewords4) . "\n\n"; // Verify: The message polynomial with EC codewords appended should be divisible by generator // This is a key property of Reed-Solomon codes $reflection = new ReflectionClass($rs); $getGeneratorMethod = $reflection->getMethod('getGeneratorPolynomial'); $getGeneratorMethod->setAccessible(true); $generator = $getGeneratorMethod->invoke($rs, 10); echo "Generator polynomial: " . implode(', ', $generator) . "\n\n"; // For RS codes, if we evaluate the encoded message at the roots of the generator polynomial, // we should get zero. But we need a decoder for that. echo "=== Reed-Solomon Properties Check ===\n"; echo "For a valid RS code:\n"; echo "1. Generator polynomial has degree = number of EC codewords ✅\n"; echo "2. EC codewords are in GF(256) ✅\n"; echo "3. All-zero message produces all-zero EC: "; echo (array_sum($ecCodewords2) === 0 ? "✅\n" : "❌\n"); // Check if EC codewords have expected properties echo "4. EC codewords are non-zero for non-zero data: "; $allZero = true; foreach ($ecCodewords1 as $ec) { if ($ec !== 0) { $allZero = false; break; } } echo (!$allZero ? "✅\n" : "❌\n");