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.
112 lines
3.6 KiB
PHP
112 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
use App\Framework\QrCode\ErrorCorrection\ReedSolomonEncoder;
|
|
|
|
echo "=== Alternative RS Implementation Test ===\n\n";
|
|
|
|
// Test with known working algorithm from qrcode.js library
|
|
// The algorithm should be:
|
|
// 1. Create message polynomial: [data, 0, 0, ..., 0] (length = data_length + ec_length)
|
|
// 2. For each data coefficient, perform polynomial division step
|
|
// 3. The key is that we divide m(x) * x^t by g(x) to get remainder
|
|
|
|
$data = [64, 180, 132, 84];
|
|
$ecCodewords = 3;
|
|
|
|
$rs = new ReedSolomonEncoder();
|
|
$reflection = new ReflectionClass($rs);
|
|
|
|
// Get generator polynomial
|
|
$getGeneratorMethod = $reflection->getMethod('getGeneratorPolynomial');
|
|
$getGeneratorMethod->setAccessible(true);
|
|
$generator = $getGeneratorMethod->invoke($rs, $ecCodewords);
|
|
|
|
echo "Data: " . implode(', ', $data) . "\n";
|
|
echo "EC codewords needed: {$ecCodewords}\n";
|
|
echo "Generator: " . implode(', ', $generator) . "\n\n";
|
|
|
|
// Try alternative algorithm: Standard RS encoding
|
|
// Message polynomial: m(x) = data[0] + data[1]*x + ... + data[n-1]*x^(n-1)
|
|
// We want to compute: (m(x) * x^t) mod g(x)
|
|
// where t = ecCodewords
|
|
|
|
// Initialize: [data, 0, 0, ..., 0]
|
|
$messagePoly = array_merge($data, array_fill(0, $ecCodewords, 0));
|
|
echo "Initial message polynomial: " . implode(', ', $messagePoly) . "\n\n";
|
|
|
|
// Standard RS division algorithm
|
|
// For each coefficient in data part:
|
|
for ($i = 0; $i < count($data); $i++) {
|
|
$lead = $messagePoly[$i];
|
|
|
|
if ($lead !== 0) {
|
|
echo "Step {$i}: lead coefficient = {$lead}\n";
|
|
echo " Before: " . implode(', ', $messagePoly) . "\n";
|
|
|
|
// In standard RS, generator is monic (leading coefficient = 1)
|
|
// So we XOR the lead coefficient directly, then multiply generator by lead
|
|
// But our generator format is [0, a1, a2, ...], meaning [1, a1, a2, ...]
|
|
|
|
// Clear the lead position (division by monic polynomial)
|
|
$messagePoly[$i] = 0;
|
|
|
|
// Apply generator coefficients (skip first 0)
|
|
$gfMultiplyMethod = $reflection->getMethod('gfMultiply');
|
|
$gfMultiplyMethod->setAccessible(true);
|
|
|
|
for ($j = 1; $j < count($generator); $j++) {
|
|
$multiplied = $gfMultiplyMethod->invoke($rs, $generator[$j], $lead);
|
|
$messagePoly[$i + $j] ^= $multiplied;
|
|
}
|
|
|
|
echo " After: " . implode(', ', $messagePoly) . "\n\n";
|
|
}
|
|
}
|
|
|
|
$ec = array_slice($messagePoly, count($data));
|
|
echo "EC codewords: " . implode(', ', $ec) . "\n\n";
|
|
|
|
// Compare with actual implementation
|
|
$actualEC = $rs->encode($data, $ecCodewords);
|
|
echo "Actual EC codewords: " . implode(', ', $actualEC) . "\n\n";
|
|
|
|
if ($ec === $actualEC) {
|
|
echo "✅ Algorithms match!\n";
|
|
} else {
|
|
echo "❌ Algorithms don't match!\n";
|
|
}
|
|
|
|
// Now test with QR code data
|
|
echo "\n=== Test with QR Code Data ===\n";
|
|
$qrData = [64, 180, 132, 84, 196, 196, 242, 5, 116, 245, 36, 196, 64, 236, 17, 236];
|
|
$qrEC = $rs->encode($qrData, 10);
|
|
|
|
echo "QR EC codewords: " . implode(', ', $qrEC) . "\n\n";
|
|
|
|
// Verify with decoder
|
|
require_once __DIR__ . '/test-reed-solomon-decoder.php';
|
|
$fullCodeword = array_merge($qrData, $qrEC);
|
|
$decoder = new SimpleRSDecoder();
|
|
$syndromes = $decoder->calculateSyndromes($fullCodeword, 10);
|
|
|
|
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";
|
|
} else {
|
|
echo "\n❌ Syndromes are not all zero - Reed-Solomon is WRONG!\n";
|
|
}
|
|
|
|
|