Files
michaelschiemer/tests/debug/test-encoding-step-by-step.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

121 lines
3.7 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\QrCode\QrCodeGenerator;
use App\Framework\QrCode\ErrorCorrection\ReedSolomonEncoder;
use App\Framework\QrCode\ValueObjects\ErrorCorrectionLevel;
use App\Framework\QrCode\ValueObjects\QrCodeConfig;
use App\Framework\QrCode\ValueObjects\QrCodeVersion;
use App\Framework\QrCode\ValueObjects\EncodingMode;
echo "=== Step-by-Step Encoding Test ===\n\n";
$testData = 'HELLO WORLD';
$config = new QrCodeConfig(
version: QrCodeVersion::fromNumber(1),
errorCorrectionLevel: ErrorCorrectionLevel::M,
encodingMode: EncodingMode::BYTE
);
echo "Test data: '{$testData}'\n";
echo "Length: " . strlen($testData) . " bytes\n\n";
// Step 1: Mode indicator
$modeBits = $config->encodingMode->getModeBits();
echo "1. Mode indicator: {$modeBits} (Byte mode)\n";
// Step 2: Character count
$charCountBits = $config->encodingMode->getCharacterCountBits($config->version);
$dataLength = strlen($testData);
$countBits = str_pad(decbin($dataLength), $charCountBits, '0', STR_PAD_LEFT);
echo "2. Character count ({$charCountBits} bits): {$countBits} = {$dataLength}\n";
// Step 3: Data bytes
$dataBitsStr = '';
for ($i = 0; $i < $dataLength; $i++) {
$byte = ord($testData[$i]);
$byteBits = str_pad(decbin($byte), 8, '0', STR_PAD_LEFT);
$dataBitsStr .= $byteBits;
echo "3.{$i} Data byte '{$testData[$i]}': {$byteBits} = {$byte}\n";
}
echo "\n";
// Step 4: Build bit string
$bits = $modeBits . $countBits . $dataBitsStr;
echo "Total bits before terminator: " . strlen($bits) . "\n";
// Step 5: Terminator
$ecInfo = ReedSolomonEncoder::getECInfo(
$config->version->getVersionNumber(),
$config->errorCorrectionLevel->value
);
$requiredBits = $ecInfo['dataCodewords'] * 8;
echo "Required bits: {$requiredBits}\n";
$terminatorLength = min(4, max(0, $requiredBits - strlen($bits)));
$bits .= str_repeat('0', $terminatorLength);
echo "Terminator bits: {$terminatorLength}\n";
echo "Bits after terminator: " . strlen($bits) . "\n\n";
// Step 6: Pad to multiple of 8
$remainder = strlen($bits) % 8;
if ($remainder !== 0) {
$bits .= str_repeat('0', 8 - $remainder);
}
echo "Bits after padding to 8: " . strlen($bits) . "\n";
// Step 7: Add pad codewords
$padBytes = ['11101100', '00010001'];
$padIndex = 0;
while (strlen($bits) < $requiredBits) {
$bits .= $padBytes[$padIndex % 2];
$padIndex++;
}
echo "Bits after pad codewords: " . strlen($bits) . "\n";
echo "Pad codewords added: {$padIndex}\n\n";
// Step 8: Convert to codewords
$codewords = [];
for ($i = 0; $i < strlen($bits); $i += 8) {
$byte = substr($bits, $i, 8);
$codewords[] = bindec($byte);
}
echo "Generated codewords (" . count($codewords) . "):\n";
echo implode(', ', $codewords) . "\n\n";
// Expected codewords
$expected = [64, 180, 132, 84, 196, 196, 242, 5, 116, 245, 174, 59, 64, 109, 236, 233];
echo "Expected codewords (16):\n";
echo implode(', ', $expected) . "\n\n";
// Compare
$matches = 0;
for ($i = 0; $i < min(count($codewords), count($expected)); $i++) {
if ($codewords[$i] === $expected[$i]) {
$matches++;
} else {
echo "❌ Codeword {$i}: got {$codewords[$i]}, expected {$expected[$i]}\n";
echo " Bits: " . substr($bits, $i * 8, 8) . " vs expected: " . str_pad(decbin($expected[$i]), 8, '0', STR_PAD_LEFT) . "\n";
}
}
if ($matches === count($expected)) {
echo "✅ All codewords match!\n";
} else {
echo "{$matches}/" . count($expected) . " codewords match\n";
}
// Show bit string breakdown
echo "\n=== Bit String Breakdown ===\n";
echo "Mode (4): " . substr($bits, 0, 4) . "\n";
echo "Count (8): " . substr($bits, 4, 8) . "\n";
echo "Data (88): " . substr($bits, 12, 88) . "\n";
echo "Terminator + Pad: " . substr($bits, 100) . "\n";