Files
michaelschiemer/tests/debug/test-syndrome-codeword-order.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

124 lines
3.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
echo "=== Syndrome Calculation with Codeword Order ===\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 "Data codewords: " . implode(', ', $data) . "\n";
echo "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]];
}
// Test 1: Forward order (data first, then EC)
$codeword1 = array_merge($data, $ec);
echo "Test 1: Forward order (data + EC)\n";
$syndromes1 = [];
for ($i = 0; $i < 10; $i++) {
$alphaPower = $gfExp[$i];
$syndrome = 0;
$power = 1;
for ($j = 0; $j < count($codeword1); $j++) {
$syndrome ^= gfMult($gfExp, $gfLog, $codeword1[$j], $power);
$power = gfMult($gfExp, $gfLog, $power, $alphaPower);
}
$syndromes1[$i] = $syndrome;
}
echo "Syndromes: " . implode(', ', $syndromes1) . "\n";
$allZero1 = array_sum($syndromes1) === 0;
echo ($allZero1 ? "" : "") . " All zero\n\n";
// Test 2: Reversed order (EC first, then data)
$codeword2 = array_merge($ec, $data);
echo "Test 2: Reversed order (EC + data)\n";
$syndromes2 = [];
for ($i = 0; $i < 10; $i++) {
$alphaPower = $gfExp[$i];
$syndrome = 0;
$power = 1;
for ($j = 0; $j < count($codeword2); $j++) {
$syndrome ^= gfMult($gfExp, $gfLog, $codeword2[$j], $power);
$power = gfMult($gfExp, $gfLog, $power, $alphaPower);
}
$syndromes2[$i] = $syndrome;
}
echo "Syndromes: " . implode(', ', $syndromes2) . "\n";
$allZero2 = array_sum($syndromes2) === 0;
echo ($allZero2 ? "" : "") . " All zero\n\n";
// Test 3: Reversed codewords (each codeword reversed)
$codeword3 = array_reverse(array_merge($data, $ec));
echo "Test 3: Reversed codewords array\n";
$syndromes3 = [];
for ($i = 0; $i < 10; $i++) {
$alphaPower = $gfExp[$i];
$syndrome = 0;
$power = 1;
for ($j = 0; $j < count($codeword3); $j++) {
$syndrome ^= gfMult($gfExp, $gfLog, $codeword3[$j], $power);
$power = gfMult($gfExp, $gfLog, $power, $alphaPower);
}
$syndromes3[$i] = $syndrome;
}
echo "Syndromes: " . implode(', ', $syndromes3) . "\n";
$allZero3 = array_sum($syndromes3) === 0;
echo ($allZero3 ? "" : "") . " All zero\n\n";
// Test 4: Polynomial representation: c[0] is highest power
// c(x) = c[0]*x^(n-1) + c[1]*x^(n-2) + ... + c[n-1]*x^0
// Evaluate at α^i: c(α^i) = sum(c[j] * (α^i)^(n-1-j))
$codeword4 = array_merge($data, $ec);
$n = count($codeword4);
echo "Test 4: MSB-first polynomial representation\n";
$syndromes4 = [];
for ($i = 0; $i < 10; $i++) {
$alphaPower = $gfExp[$i];
$syndrome = 0;
// Start with (α^i)^(n-1)
$power = $gfExp[($i * ($n - 1)) % 255];
for ($j = 0; $j < $n; $j++) {
$syndrome ^= gfMult($gfExp, $gfLog, $codeword4[$j], $power);
// Next: divide by α^i
$power = gfMult($gfExp, $gfLog, $power, $gfExp[255 - $i]);
}
$syndromes4[$i] = $syndrome;
}
echo "Syndromes: " . implode(', ', $syndromes4) . "\n";
$allZero4 = array_sum($syndromes4) === 0;
echo ($allZero4 ? "" : "") . " All zero\n\n";
if ($allZero1 || $allZero2 || $allZero3 || $allZero4) {
echo "✅ Found correct order!\n";
} else {
echo "❌ None of the orders work. The syndrome calculation might be fundamentally wrong.\n";
}