Files
michaelschiemer/tests/debug/test-reed-solomon-reference.php
Michael Schiemer 95147ff23e refactor(deployment): Remove WireGuard VPN dependency and restore public service access
Remove WireGuard integration from production deployment to simplify infrastructure:
- Remove docker-compose-direct-access.yml (VPN-bound services)
- Remove VPN-only middlewares from Grafana, Prometheus, Portainer
- Remove WireGuard middleware definitions from Traefik
- Remove WireGuard IPs (10.8.0.0/24) from Traefik forwarded headers

All monitoring services now publicly accessible via subdomains:
- grafana.michaelschiemer.de (with Grafana native auth)
- prometheus.michaelschiemer.de (with Basic Auth)
- portainer.michaelschiemer.de (with Portainer native auth)

All services use Let's Encrypt SSL certificates via Traefik.
2025-11-05 12:48:25 +01:00

86 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\QrCode\ErrorCorrection\ReedSolomonEncoder;
echo "=== Reed-Solomon Reference Test ===\n\n";
// Known test vectors from QR code specification
// For Version 1, Level M: 16 data codewords, 10 EC codewords
// Test Case 1: Simple known data
echo "Test Case 1: Simple data\n";
$testData1 = [1, 2, 3, 4, 5];
$ec1 = 5;
$rs = new ReedSolomonEncoder();
$ecCodewords1 = $rs->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");