当前位置:网站首页>PHP converts strings to hex and hex to string - PHP convert string to hex and hex to string

PHP converts strings to hex and hex to string - PHP convert string to hex and hex to string

2022-06-25 06:37:00 Rich in starch

problem :

I got the problem when convert between this 2 type in PHP. stay PHP In this 2 There was a problem converting between types .This is the code I searched in google This is the code I searched in Google

function strToHex($string){    $hex='';    for ($i=0; $i < strlen($string); $i++){        $hex .= dechex(ord($string[$i]));    }    return $hex;}function hexToStr($hex){    $string='';    for ($i=0; $i < strlen($hex)-1; $i+=2){        $string .= chr(hexdec($hex[$i].$hex[$i+1]));    }    return $string;}

I check it and found out this when I use XOR to encrypt. I check it and use it XOR This was discovered during encryption .

I have the string "this is the test" , after XOR with a key, I have the result in string ↑§P§P *§T§ . I have a string "this is the test" , After using a key XOR , My result is a string ↑§P§P *§T§ .After that, I tried to convert it to hex by function strToHex() and I got these 12181d15501d15500e15541215712 . after , I try to use the function strToHex() Convert it to hexadecimal , I got these 12181d15501d15500e15541215712 .Then, I tested with the function hexToStr() and I have ↑§P§P*§T§q . then , I use functions hexToStr() Tested , I have a ↑§P§P*§T§q .So, what should I do to solve this problem? that , What should I do to solve this problem ?Why does it wrong when I convert this 2 style value? Why do I switch this 2 An error occurs when a style value is ?


Solution :

Reference resources : https://stackoom.com/en/question/zZas
原网站

版权声明
本文为[Rich in starch]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202201234260393.html