我必须将旧的“加密”数据从旧系统转换为适当的加密算法。我有这个代码:
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