/**
* Encryption of simple symmetric encryption algorithm
* @param string $string strings that need to be encrypted
* @param String $skey Encryption Eky
* @return String
*/
function encode ($string = ', $skey = ' textphp ') {
$skey = Str_split (Base64_encode ($skey));
$STRARR = Str_split (Base64_encode ($string));
$strCount = count ($STRARR);
foreach ($skey as $key = = $value) {
$key < $strCount && $strArr [$key].= $value;
}
return str_replace (' = ', ' o0o0o ', join (', $STRARR));
}
/**
* Decryption of simple symmetric encryption algorithm
* @param string $string A string to decrypt
* @param String $skey Decrypt key
* @return String
*/
function decode ($string = ', $skey = ' textphp ') {
$skey = Str_split (Base64_encode ($skey));
$STRARR = Str_split (Str_replace (' o0o0o ', ' = ', $string), 2);
$strCount = count ($STRARR);
foreach ($skey as $key = = $value) {
$key < $strCount && $STRARR [$key][1] = = = $value && $strArr [$key] = $STRARR [$key][0];
}
Return Base64_decode (Join (', $STRARR));
}
String converted to 16 binary
function Str2hex ($str, $encoded = ' GBK ') {
$hex = ";
if ($encoded = = ' GBK ') {
$str = mb_convert_encoding ($str, ' GBK ', ' UTF-8 ');
}
for ($i = 0, $length = Mb_strlen ($STR); $i < $length; $i + +) {
$hex. = Dechex (Ord ($str {$i}));
}
return $hex;
}
16 binary converted to string
function Hex2str ($hex, $encoded = ' GBK ') {
$str = ";
$arr = Str_split ($hex, 2);
foreach ($arr as $bit) {
$str. = Chr (Hexdec ($bit));
}
if ($encoded = = ' GBK ') {
$str = mb_convert_encoding ($str, ' UTF-8 ', ' GBK ');
}
return $str;
}
This paper introduces the php-simple symmetric encryption algorithm and the reciprocal function between the string and hexadecimal, including the contents of the content, I hope to be interested in the PHP tutorial friends helpful.