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

113 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
echo "=== Pad Codewords Analysis ===\n\n";
// For "HELLO WORLD", Version 1, Level M:
// - Mode: 4 bits (0100)
// - Count: 8 bits (00001011)
// - Data: 11 bytes = 88 bits
// - Total so far: 100 bits
// - Required: 128 bits (16 codewords * 8)
// - Need: 28 more bits
echo "Bit breakdown:\n";
echo "Mode: 4 bits\n";
echo "Count: 8 bits\n";
echo "Data: 88 bits (11 bytes)\n";
echo "Subtotal: 100 bits\n";
echo "Required: 128 bits\n";
echo "Needed: 28 bits\n\n";
// Terminator: 4 bits (0000)
$terminator = "0000";
echo "After terminator: 104 bits\n";
// Pad to multiple of 8: 104 is already multiple of 8
echo "After padding to 8: 104 bits\n";
// Need 24 more bits (3 pad codewords)
$padBytes = ['11101100', '00010001'];
$padSequence = $padBytes[0] . $padBytes[1] . $padBytes[0];
echo "Pad sequence (24 bits): {$padSequence}\n\n";
// So the full bit string should be:
$fullBits = "0100" . // Mode
"00001011" . // Count
"0100100001000101010011000100110001001111001000000101011101001111010100100100110001000100" . // Data (88 bits)
"0000" . // Terminator
$padSequence; // 24 bits
echo "Full bit string (128 bits):\n";
echo $fullBits . "\n\n";
// Convert to codewords
$codewords = [];
for ($i = 0; $i < 128; $i += 8) {
$byte = substr($fullBits, $i, 8);
$codewords[] = bindec($byte);
}
echo "Codewords from our calculation:\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:\n";
echo implode(', ', $expected) . "\n\n";
// Compare bit by bit
echo "=== Bit-by-Bit Comparison ===\n";
for ($i = 0; $i < 16; $i++) {
$ourBits = str_pad(decbin($codewords[$i]), 8, '0', STR_PAD_LEFT);
$expectedBits = str_pad(decbin($expected[$i]), 8, '0', STR_PAD_LEFT);
if ($ourBits !== $expectedBits) {
echo "❌ Codeword {$i}: {$ourBits} vs {$expectedBits}\n";
// Show which bits differ
for ($j = 0; $j < 8; $j++) {
if ($ourBits[$j] !== $expectedBits[$j]) {
echo " Bit {$j} differs: got '{$ourBits[$j]}', expected '{$expectedBits[$j]}'\n";
}
}
} else {
echo "✅ Codeword {$i}: {$ourBits}\n";
}
}
// Let's check what the expected codewords represent in bits
echo "\n=== Expected Bit String ===\n";
$expectedBitString = '';
foreach ($expected as $codeword) {
$expectedBitString .= str_pad(decbin($codeword), 8, '0', STR_PAD_LEFT);
}
echo "Expected bit string (128 bits):\n";
echo $expectedBitString . "\n\n";
// Compare with our bit string
echo "Our bit string (128 bits):\n";
echo $fullBits . "\n\n";
$differences = 0;
for ($i = 0; $i < 128; $i++) {
if ($fullBits[$i] !== $expectedBitString[$i]) {
$differences++;
if ($differences <= 10) {
echo "Bit {$i} differs: got '{$fullBits[$i]}', expected '{$expectedBitString[$i]}'\n";
}
}
}
if ($differences === 0) {
echo "✅ Bit strings match!\n";
} else {
echo "{$differences} bits differ\n";
}