Files
michaelschiemer/tests/debug/test-reed-solomon-verification.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

114 lines
3.9 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\QrCode\ErrorCorrection\ReedSolomonEncoder;
echo "=== Reed-Solomon Verification ===\n\n";
// Test with known data codewords for "HELLO WORLD"
// These are the correct data codewords that we generate
$dataCodewords = [64, 180, 132, 84, 196, 196, 242, 5, 116, 245, 36, 196, 64, 236, 17, 236];
echo "Data codewords (16):\n";
echo implode(', ', $dataCodewords) . "\n\n";
// Generate EC codewords
$reedSolomon = new ReedSolomonEncoder();
$ecCodewords = $reedSolomon->encode($dataCodewords, 10);
echo "EC codewords (10):\n";
echo implode(', ', $ecCodewords) . "\n\n";
// Verify Reed-Solomon encoding
// For Reed-Solomon, if we encode data and then decode, we should get the original data back
// But we can also verify by checking if the polynomial division was correct
echo "=== Reed-Solomon Verification ===\n";
echo "For RS(n, k), where n = total codewords and k = data codewords:\n";
echo " n = 26 (total codewords)\n";
echo " k = 16 (data codewords)\n";
echo " t = 10 (EC codewords)\n";
echo " Can correct up to t/2 = 5 errors\n\n";
// Test: Create a message polynomial and verify encoding
echo "Message polynomial (data + zeros for EC):\n";
$messagePoly = array_merge($dataCodewords, array_fill(0, 10, 0));
echo " " . implode(', ', $messagePoly) . "\n\n";
// Get generator polynomial
$reflection = new ReflectionClass($reedSolomon);
$getGeneratorMethod = $reflection->getMethod('getGeneratorPolynomial');
$getGeneratorMethod->setAccessible(true);
$generator = $getGeneratorMethod->invoke($reedSolomon, 10);
echo "Generator polynomial (degree 10):\n";
echo " " . implode(', ', $generator) . "\n\n";
// Verify: The generator polynomial should have 11 coefficients (degree 10 + 1)
if (count($generator) === 11) {
echo "✅ Generator polynomial has correct degree (10)\n";
} else {
echo "❌ Generator polynomial has wrong degree: " . (count($generator) - 1) . " (expected: 10)\n";
}
// Test GF field operations
echo "\n=== GF(256) Field Operations Test ===\n";
$gfMultiplyMethod = $reflection->getMethod('gfMultiply');
$gfMultiplyMethod->setAccessible(true);
// Test some multiplications
$testCases = [
[0, 5, 0], // 0 * anything = 0
[1, 5, 5], // 1 * x = x
[2, 3, 6], // 2 * 3 = 6
[87, 1, 87], // Generator coefficient
[251, 1, 251], // Generator coefficient
];
$allCorrect = true;
foreach ($testCases as [$a, $b, $expected]) {
$result = $gfMultiplyMethod->invoke($reedSolomon, $a, $b);
$match = $result === $expected ? '✅' : '❌';
if ($result !== $expected) {
$allCorrect = false;
}
echo " {$a} * {$b} = {$result} (expected: {$expected}) {$match}\n";
}
if ($allCorrect) {
echo "\n✅ GF multiplication is correct\n";
} else {
echo "\n❌ GF multiplication has errors\n";
}
// Test generator polynomial coefficients
echo "\n=== Generator Polynomial Coefficients ===\n";
echo "Expected for 10 EC codewords (from QR spec):\n";
echo " [0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45]\n";
echo "Actual:\n";
echo " [" . implode(', ', $generator) . "]\n";
if ($generator === [0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45]) {
echo "\n✅ Generator polynomial matches specification!\n";
} else {
echo "\n❌ Generator polynomial doesn't match specification!\n";
echo "Differences:\n";
$expected = [0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45];
for ($i = 0; $i < min(count($generator), count($expected)); $i++) {
if ($generator[$i] !== $expected[$i]) {
echo " Coefficient {$i}: got {$generator[$i]}, expected {$expected[$i]}\n";
}
}
}
// Final check: Can we decode the encoded data?
echo "\n=== Decode Test ===\n";
echo "Note: Full decode test requires error correction decoder.\n";
echo "For now, we verify that EC codewords are generated correctly.\n";
echo "If EC codewords are wrong, QR scanners will fail the error correction check.\n";