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
How to Dynamically Set Table Name in Eloquent Model
File Upload PHP $_Files Undefined Index Error
Attach Image to Facebook Event (PHP Sdk, Rest or Graph API)
Google Calendar API Batch Request PHP
Insert Multiple Data into Database in Yii 2
Laravel Get Route Name from Given Url
Dompdf - Attach Created PDF to Email
Session Share Across Multiple Domains on Same Server
Phpunit: Doing Assertions on Non-Public Variables
Need to Merge Multiple PDF's into a Single PDF with Table of Contents Sections
Mysql: Get Total in Last Row of MySQL Result
How to Get/Set Session_Id() or Should It Be Generated Automatically
Using PHP, How to Insert Text Without Overwriting to the Beginning of a Text File
File_Get_Contents Is Not Working for Some Url