Convert Hex Code into Readable String in PHP

Convert Hex Code into readable string in PHP

It seems your code is obfuscated not only with hex escape sequences, but with octal as well. I've written this function to decode it for you:

function decode_code($code){
return preg_replace_callback(
"@\\\(x)?([0-9a-f]{2,3})@",
function($m){
return chr($m[1]?hexdec($m[2]):octdec($m[2]));
},
$code
);
}

See it in action here: http://codepad.viper-7.com/NjiL84

Convert hex to ascii characters

You can trivially adapt the solution I presented here using the function base_convert_arbitrary.

Edit: I had not read carefully enough :) Base 16 to base 62 is still very doable, as above.

See it in action.

OTP or S/KEY - Conversion of Hex string into 6 readable words

There's no need to convert to decimal. If your hex value is a string, just convert it to a number (for example, with Integer.valueOf(value, 16)). Then use that number to look up the word. If you can store the whole dictionary in memory, use the number as the index. If you can't store it in memory, use it to control how far into the dictionary file you look (if every item is on a separate line, read that many lines into the file). If you've got a database somewhere, use the number as the table's key and select by key.

How can I get a hex dump of a string in PHP?

echo bin2hex($string);

or:

for ($i = 0; $i < strlen($string); $i++) {
echo str_pad(dechex(ord($string[$i])), 2, '0', STR_PAD_LEFT);
}

$string is the variable which contains input.



Related Topics



Leave a reply



Submit