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.
129 lines
4.1 KiB
PHP
129 lines
4.1 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||
|
||
use App\Framework\QrCode\ErrorCorrection\ReedSolomonEncoder;
|
||
|
||
echo "=== Syndrome Calculation with Generator Roots ===\n\n";
|
||
|
||
// Reference data and EC codewords
|
||
$data = [64, 180, 132, 84, 196, 196, 242, 5, 116, 245, 174, 59, 64, 109, 236, 233];
|
||
$ec = [0, 245, 228, 127, 21, 207, 194, 102, 66, 52];
|
||
|
||
echo "Reference data codewords: " . implode(', ', $data) . "\n";
|
||
echo "Reference EC codewords: " . implode(', ', $ec) . "\n\n";
|
||
|
||
// Initialize GF(256)
|
||
$gfLog = array_fill(0, 256, 0);
|
||
$gfExp = array_fill(0, 512, 0);
|
||
|
||
$x = 1;
|
||
for ($i = 0; $i < 255; $i++) {
|
||
$gfExp[$i] = $x;
|
||
$gfLog[$x] = $i;
|
||
$x <<= 1;
|
||
if ($x & 0x100) {
|
||
$x ^= 0x11d;
|
||
}
|
||
}
|
||
|
||
for ($i = 255; $i < 512; $i++) {
|
||
$gfExp[$i] = $gfExp[$i - 255];
|
||
}
|
||
|
||
function gfMult(array $gfExp, array $gfLog, int $a, int $b): int
|
||
{
|
||
if ($a === 0 || $b === 0) return 0;
|
||
return $gfExp[$gfLog[$a] + $gfLog[$b]];
|
||
}
|
||
|
||
// Get generator polynomial
|
||
$rs = new ReedSolomonEncoder();
|
||
$reflection = new \ReflectionClass($rs);
|
||
$getGeneratorMethod = $reflection->getMethod('getGeneratorPolynomial');
|
||
$getGeneratorMethod->setAccessible(true);
|
||
$generator = $getGeneratorMethod->invoke($rs, 10);
|
||
|
||
echo "Generator polynomial: " . implode(', ', $generator) . "\n";
|
||
echo "Note: This represents g(x) = (x-α^0)(x-α^1)...(x-α^9)\n\n";
|
||
|
||
// The generator roots are α^0, α^1, ..., α^9
|
||
// For a valid codeword, c(α^i) should be 0 for i = 0 to 9
|
||
|
||
$fullCodeword = array_merge($data, $ec);
|
||
echo "Full codeword: " . implode(', ', $fullCodeword) . "\n\n";
|
||
|
||
// Test: Evaluate codeword polynomial at generator roots
|
||
echo "=== Evaluating at Generator Roots ===\n";
|
||
echo "For a valid RS codeword, c(α^i) should be 0 for all generator roots.\n\n";
|
||
|
||
// Standard RS: c(x) = c[0] + c[1]*x + c[2]*x^2 + ... + c[n-1]*x^(n-1)
|
||
// But QR codes might use different polynomial representation
|
||
|
||
// Test 1: Standard polynomial (LSB-first)
|
||
echo "Test 1: Standard polynomial c(x) = c[0] + c[1]*x + ...\n";
|
||
$syndromes1 = [];
|
||
for ($i = 0; $i < 10; $i++) {
|
||
$alphaPower = $gfExp[$i];
|
||
$syndrome = 0;
|
||
$power = 1; // x^0 = 1
|
||
for ($j = 0; $j < count($fullCodeword); $j++) {
|
||
$syndrome ^= gfMult($gfExp, $gfLog, $fullCodeword[$j], $power);
|
||
$power = gfMult($gfExp, $gfLog, $power, $alphaPower);
|
||
}
|
||
$syndromes1[$i] = $syndrome;
|
||
echo " c(α^{$i}) = {$syndrome}\n";
|
||
}
|
||
$allZero1 = array_sum($syndromes1) === 0;
|
||
echo ($allZero1 ? "✅" : "❌") . " All syndromes are zero\n\n";
|
||
|
||
// Test 2: Reversed polynomial (MSB-first)
|
||
// c(x) = c[0]*x^(n-1) + c[1]*x^(n-2) + ... + c[n-1]
|
||
echo "Test 2: Reversed polynomial c(x) = c[0]*x^(n-1) + c[1]*x^(n-2) + ...\n";
|
||
$n = count($fullCodeword);
|
||
$syndromes2 = [];
|
||
for ($i = 0; $i < 10; $i++) {
|
||
$alphaPower = $gfExp[$i];
|
||
$syndrome = 0;
|
||
// Start with x^(n-1) evaluated at α^i
|
||
$power = $gfExp[($i * ($n - 1)) % 255];
|
||
for ($j = 0; $j < $n; $j++) {
|
||
$syndrome ^= gfMult($gfExp, $gfLog, $fullCodeword[$j], $power);
|
||
// Divide by α^i (multiply by α^(255-i))
|
||
$power = gfMult($gfExp, $gfLog, $power, $gfExp[255 - $i]);
|
||
}
|
||
$syndromes2[$i] = $syndrome;
|
||
echo " c(α^{$i}) = {$syndrome}\n";
|
||
}
|
||
$allZero2 = array_sum($syndromes2) === 0;
|
||
echo ($allZero2 ? "✅" : "❌") . " All syndromes are zero\n\n";
|
||
|
||
// Test 3: Maybe we need to evaluate at different roots?
|
||
// Generator: g(x) = (x-α^0)(x-α^1)...(x-α^9)
|
||
// But maybe the roots are α^1, α^2, ..., α^10?
|
||
echo "Test 3: Evaluating at α^1 to α^10 (shifted roots)\n";
|
||
$syndromes3 = [];
|
||
for ($i = 1; $i <= 10; $i++) {
|
||
$alphaPower = $gfExp[$i];
|
||
$syndrome = 0;
|
||
$power = 1;
|
||
for ($j = 0; $j < count($fullCodeword); $j++) {
|
||
$syndrome ^= gfMult($gfExp, $gfLog, $fullCodeword[$j], $power);
|
||
$power = gfMult($gfExp, $gfLog, $power, $alphaPower);
|
||
}
|
||
$syndromes3[$i - 1] = $syndrome;
|
||
echo " c(α^{$i}) = {$syndrome}\n";
|
||
}
|
||
$allZero3 = array_sum($syndromes3) === 0;
|
||
echo ($allZero3 ? "✅" : "❌") . " All syndromes are zero\n\n";
|
||
|
||
if ($allZero1 || $allZero2 || $allZero3) {
|
||
echo "✅ Found correct evaluation method!\n";
|
||
} else {
|
||
echo "❌ None of the methods work. The problem might be in the generator polynomial.\n";
|
||
}
|
||
|
||
|