1<?PHP2 /**3 * Encryption of simple symmetric encryption algorithm4 * @param string $string strings that need to be encrypted5 * @param String $skey encryption Eky6 * @return String7 */8 functionEncode$string= ",$skey= ' testphp ') {9 $skey=Str_split(Base64_encode($skey));Ten $STRARR=Str_split(Base64_encode($string)); One $strCount=Count($STRARR); A foreach($skey as $key=$value) { - $key<$strCount&&$STRARR[$key].=$value; - } the return Str_replace(' = ', ' o0o0o ',Join(‘‘,$STRARR)); - } - - /** + * Decryption of simple symmetric encryption algorithm - * @param string $string A string to decrypt + * @param String $skey Decrypt key A * @return String at */ - functionDecode$string= ",$skey= ' testphp ') { - $skey=Str_split(Base64_encode($skey)); - $STRARR=Str_split(Str_replace(' o0o0o ', ' = ',$string), 2); - $strCount=Count($STRARR); - foreach($skey as $key=$value) { in $key<$strCount&&$STRARR[$key][1] = = =$value&&$STRARR[$key] =$STRARR[$key][0]; - } to return Base64_decode(Join(‘‘,$STRARR)); + } - the //string converted to 16 binary * functionStr2hex ($str,$encoded= ' GBK ') { $ $hex= ' ';Panax Notoginseng if($encoded= = ' GBK ') { - $str= Mb_convert_encoding ($str, ' GBK ', ' UTF-8 '); the } + for($i= 0,$length= Mb_strlen ($str);$i<$length;$i++) { A $hex.=Dechex(Ord($str{$i})); the } + return $hex; - } $ $ //16 binary converted to string - functionHEX2STR ($hex,$encoded= ' GBK ') { - $str= ' '; the $arr=Str_split($hex, 2); - foreach($arr as $bit) {Wuyi $str.=CHR(Hexdec($bit)); the } - if($encoded= = ' GBK ') { Wu $str= Mb_convert_encoding ($str, ' UTF-8 ', ' GBK '); - } About return $str; $}
php-simple symmetric encryption algorithm and reciprocal transfer function between string and hexadecimal