'L', '00' => 'M', '11' => 'Q', '10' => 'H' } . "\n"; echo " Mask: " . substr($ourUnmasked, 2, 3) . " = Pattern " . bindec(substr($ourUnmasked, 2, 3)) . "\n\n"; echo "Decoding Python Format Info:\n"; $pythonUnmasked = ''; for ($i = 0; $i < 15; $i++) { $pythonUnmasked .= (int)$pythonFormatH[$i] ^ (int)$xorMask[$i]; } echo " Unmasked: {$pythonUnmasked}\n"; echo " EC: " . substr($pythonUnmasked, 0, 2) . " = " . match(substr($pythonUnmasked, 0, 2)) { '01' => 'L', '00' => 'M', '11' => 'Q', '10' => 'H' } . "\n"; echo " Mask: " . substr($pythonUnmasked, 2, 3) . " = Pattern " . bindec(substr($pythonUnmasked, 2, 3)) . "\n\n"; echo "=== Conclusion ===\n"; echo "Our implementation uses Mask Pattern 2\n"; echo "Python reference uses Mask Pattern 0\n"; echo "This explains the data differences!\n";