我需要将旧系统中的一些“加密”数据转换为现代加密算法。以下是代码:
function unpackString($s,$l){
$tmp=unpack('c'.$l,$s);
$return=NULL;
foreach($tmp as $v){
if($v>0){
$return.=chr($v);
}
}
return $return;
}
function packString($s,$l){
$return=NULL;
for($i=0;$i<$l;$i++){
$return.=pack('c',ord(substr($s,$i,1)));
}
return $return;
}
$string='StackOverflow Is AWESOME';
$l=strlen($string);
$encoded=packString(base64_encode($string),$l);
$decoded=base64_decode(unpackString($encoded,$l));
echo "\n".$decoded."\n";
为什么输出显示为
StackOverflow Is A
而不是StackOverflow Is AWESOME
?