[0xFF, 0xD8], 'png' => [0x89, 0x50], 'gif' => [0x47, 0x49], ]; foreach ($header as $ext => $hex) { $strInfo = @unpack("C2chars", $twoByte); $password = $strInfo['chars1'] ^ $hex[0]; $charCheck1 = $strInfo['chars1'] ^ $password; $charCheck2 = $strInfo['chars2'] ^ $password; if ($charCheck1 == $hex[0] && $charCheck2 == $hex[1]) { return ['ext' => $ext, 'password' => $password]; } } return null; }