/**
* 簡單對稱加密演算法加密
* @param String $string 需要加密的字符串
* @param String $skey 加密EKY
* @return String
*/
函式編碼($string = '', $skey = 'textphp') {
$skey = str_split(base64_encode($skey));
$strArr = str_split(64_enencode( $string) ));
$strCount = count($strArr);
foreach ($skey as $key => $value) {
$key
return str_replace('=', 'O0O0O', join('', $strArr));
}
/**
* 簡單對稱加密演算法解密
* @param String $string 需要解密的字符串
* @param String $skey 解密KEY
* @return String
*/
函數解碼($string = '', $skey = 'textphp') {
$skey = str_split(base64_encode($skey));
$strArr = strplace_split(str_replace( 'O0O0O) ', '=', $string), 2);
$strCount = count($strArr);
foreach ($skey as $key => $value) {
$key }
return base64_decode(join('', $strArr ) )) ;
}
//字串轉換成16位元舞蹈
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 $hex .= dechex (ord($str{$i}));
回傳$hex;
}
//16 轉轉換成字串
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( 'UTF-8', 'GBK' );
回傳$str;
}
🎜 以上就介紹了php-簡單的加密演算法和字串與十六進位之間的互轉函數,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。 🎜 🎜