<?php

header("content-type:text/html;charset=utf-8");

/**
*@param $string目标字符串
*@param $key 加密key
*@return string
*/
function encryption($string="",$key="cxphp"){
//str_split把字符串分割到数组中
$strArr = str_split(base64_encode($string));
$strcount = count($strArr);
foreach(str_split($key) as $key=>$value){
$key < $strcount && $strArr[$key].= $value;
return str_replace(array('=','+','/'), array('O0O0O', 'o000o', 'oo00o'), join($strArr));
}
}

/**
*@param $string 解析字符串
*@param $key 揭秘到key
*@return string
*/
function deciphering($string='',$skey='cxphp'){
$strArr = str_split(str_replace(array('O0O0O', 'o000o', 'oo00o'), array('=', '+', '/'), $string), 2);
$strCount = count($strArr);
foreach (str_split($skey) as $key => $value)
$key <= $strCount && @$strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0];
return base64_decode(join($strArr));
}

$a = encryption('这是我的一条测试数据');
var_dump($a);

$a = '6cLo000oZ5piv5oiR55qE5LiA5p2h5rWL6Ko000oV5pWw5o2u';

$b = deciphering($a);
var_dump($b);