Files
michaelschiemer/tests/debug/test-data-codewords-detail.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

105 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
echo "=== Data Codewords Detail Analysis ===\n\n";
$testData = 'HELLO WORLD';
// Build our encoding
$bits = '';
// 1. Mode indicator (4 bits) - Byte mode = 0100
$bits .= '0100';
// 2. Character count (8 bits)
$bits .= str_pad(decbin(11), 8, '0', STR_PAD_LEFT);
// 3. Data bytes - let's check each one
echo "Data bytes:\n";
for ($i = 0; $i < 11; $i++) {
$char = $testData[$i];
$byte = ord($char);
$byteBits = str_pad(decbin($byte), 8, '0', STR_PAD_LEFT);
$bits .= $byteBits;
echo " '{$char}' (ASCII {$byte}): {$byteBits}\n";
}
echo "\nTotal bits: " . strlen($bits) . "\n";
echo "Bit string: {$bits}\n\n";
// Convert to codewords
$codewords = [];
for ($i = 0; $i < strlen($bits); $i += 8) {
if ($i + 8 <= strlen($bits)) {
$byte = substr($bits, $i, 8);
$codewords[] = bindec($byte);
echo "Codeword " . count($codewords) . " (bits " . $i . "-" . ($i+7) . "): {$byte} = " . bindec($byte) . "\n";
} else {
// Partial byte
$byte = substr($bits, $i);
echo "Partial byte (bits " . $i . "-" . (strlen($bits)-1) . "): {$byte}\n";
}
}
// Expected codewords
$expected = [64, 180, 132, 84, 196, 196, 242, 5, 116, 245, 174, 59, 64, 109, 236, 233];
echo "\n=== Expected Codewords ===\n";
$expectedBits = '';
for ($i = 0; $i < count($expected); $i++) {
$byteBits = str_pad(decbin($expected[$i]), 8, '0', STR_PAD_LEFT);
$expectedBits .= $byteBits;
echo "Codeword " . ($i + 1) . ": {$byteBits} = {$expected[$i]}\n";
}
echo "\n=== Comparison ===\n";
echo "Our bit string (first 100 bits):\n";
echo substr($bits, 0, 100) . "\n\n";
echo "Expected bit string (first 100 bits):\n";
echo substr($expectedBits, 0, 100) . "\n\n";
// Find first difference
for ($i = 0; $i < min(strlen($bits), 100); $i++) {
if ($bits[$i] !== $expectedBits[$i]) {
$codewordIndex = intval($i / 8);
$bitInCodeword = $i % 8;
echo "❌ First difference at bit {$i} (codeword " . ($codewordIndex + 1) . ", bit {$bitInCodeword})\n";
echo " Our bit: {$bits[$i]}\n";
echo " Expected: {$expectedBits[$i]}\n";
// Show codeword context
$codewordStart = $codewordIndex * 8;
echo " Codeword " . ($codewordIndex + 1) . ":\n";
echo " Our: " . substr($bits, $codewordStart, 8) . " = " . (isset($codewords[$codewordIndex]) ? $codewords[$codewordIndex] : 'N/A') . "\n";
echo " Expected: " . substr($expectedBits, $codewordStart, 8) . " = " . $expected[$codewordIndex] . "\n";
// Show surrounding context
echo " Context (bits " . max(0, $codewordStart - 8) . "-" . min(strlen($bits), $codewordStart + 16) . "):\n";
echo " Our: " . substr($bits, max(0, $codewordStart - 8), min(24, strlen($bits) - max(0, $codewordStart - 8))) . "\n";
echo " Expected: " . substr($expectedBits, max(0, $codewordStart - 8), min(24, strlen($expectedBits) - max(0, $codewordStart - 8))) . "\n";
break;
}
}
// Check if our data matches expected data
echo "\n=== Data Codewords Check ===\n";
echo "Our first 12 codewords: " . implode(', ', array_slice($codewords, 0, 12)) . "\n";
echo "Expected first 12 codewords: " . implode(', ', array_slice($expected, 0, 12)) . "\n";
$match = true;
for ($i = 0; $i < min(12, count($codewords), count($expected)); $i++) {
if ($codewords[$i] !== $expected[$i]) {
$match = false;
echo "❌ Codeword " . ($i + 1) . " differs: ours={$codewords[$i]}, expected={$expected[$i]}\n";
}
}
if ($match) {
echo "✅ First 12 codewords match!\n";
} else {
echo "❌ Data codewords don't match!\n";
}