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.
107 lines
2.8 KiB
PHP
107 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
echo "=== Correct RS Algorithm Test ===\n\n";
|
|
|
|
// Initialize GF(256) - same as in ReedSolomonEncoder
|
|
$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]];
|
|
}
|
|
|
|
// Correct RS encoding algorithm
|
|
function rsEncodeCorrect(array $data, int $ecCodewords, array $gfExp, array $gfLog): array
|
|
{
|
|
// Generator polynomial from specification
|
|
// Format: [0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45] for 10 EC codewords
|
|
// This represents: g(x) = x^10 + 251*x^9 + 67*x^8 + ... + 45
|
|
$generators = [
|
|
10 => [0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45],
|
|
];
|
|
|
|
if (!isset($generators[$ecCodewords])) {
|
|
throw new Exception("No generator for {$ecCodewords} EC codewords");
|
|
}
|
|
|
|
$generator = $generators[$ecCodewords];
|
|
|
|
// Message polynomial: [data, 0, 0, ..., 0]
|
|
$msg = array_merge($data, array_fill(0, $ecCodewords, 0));
|
|
|
|
// Polynomial division
|
|
// Generator format [0, a1, a2, ...] means leading coefficient is 1
|
|
for ($i = 0; $i < count($data); $i++) {
|
|
$lead = $msg[$i];
|
|
|
|
if ($lead !== 0) {
|
|
// Clear leading position (division by monic polynomial)
|
|
$msg[$i] = 0;
|
|
|
|
// Apply generator coefficients
|
|
// generator[0] = 0 means leading coeff = 1, so we start at j=1
|
|
for ($j = 1; $j < count($generator); $j++) {
|
|
if ($i + $j < count($msg)) {
|
|
$msg[$i + $j] ^= gfMult($gfExp, $gfLog, $generator[$j], $lead);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return array_slice($msg, count($data));
|
|
}
|
|
|
|
// Test
|
|
$data = [64, 180, 132, 84, 196, 196, 242, 5, 116, 245, 36, 196, 64, 236, 17, 236];
|
|
$ecCodewords = 10;
|
|
|
|
echo "Data: " . implode(', ', $data) . "\n\n";
|
|
|
|
$ec = rsEncodeCorrect($data, $ecCodewords, $gfExp, $gfLog);
|
|
|
|
echo "EC codewords: " . implode(', ', $ec) . "\n\n";
|
|
|
|
// Verify
|
|
require_once __DIR__ . '/test-reed-solomon-decoder.php';
|
|
$full = array_merge($data, $ec);
|
|
$decoder = new SimpleRSDecoder();
|
|
$syndromes = $decoder->calculateSyndromes($full, $ecCodewords);
|
|
|
|
echo "Syndromes: " . implode(', ', $syndromes) . "\n";
|
|
$allZero = true;
|
|
foreach ($syndromes as $s) {
|
|
if ($s !== 0) {
|
|
$allZero = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($allZero) {
|
|
echo "\n✅ ALL SYNDROMES ARE ZERO - Reed-Solomon is CORRECT!\n";
|
|
echo "\nThis is the correct algorithm. We need to update our implementation.\n";
|
|
} else {
|
|
echo "\n❌ Still wrong!\n";
|
|
}
|
|
|
|
|