请各位朋友 帮忙看看 下面php代码哪里错了

WBOY
Release: 2016-06-23 13:50:18
Original
1021 people have browsed it

鄙人刚刚学习PHP  ,遇到了不少的麻烦 ,希望有空的朋友  帮忙看看下面代码 哪里出错了
代码是一段 “与或” 加密、解密----字符的  加密的这部分结果是对的  但语法还是有点问题  解密的就完全有问题了
求指点!谢谢了!

<? header('content-type:text/html;charset=utf8');$key=array();$key[0]=1;$key[1]=2;$key[2]=3;$key[3]=4;$key[4]=5;$key[5]=6;$key[6]=7;$key[7]=8;$key[8]=9;$key[9]=10;$mystring="我擦擦"; $jiamistring=PassEncode($mystring); Echo " 加密=";Echo $jiamistring;$jiemistring=PassUnCode($jiamistring);Echo " 解密=";Echo $jiemistring;function PassEncode($s)//加密{  global $key;  $Buff = str_split($s);  $k=count($key)+1;  for ($I=0; $I<count($Buff); $I=$I+1)  {    $j=$I%$k;    $string=utf8_unicode($Buff[$I]);    $Buff[$I]=$string ^ $key[$j];  }   $mstr="0123456789";  $outstr="";  for ($I=0; $I<count($Buff); $I=$I+1)  {    $k=floor($Buff[$I]/strlen($mstr));    $j=$Buff[$I]%strlen($mstr);    $temps="$mstr[$j]"."$mstr[$k]";    $outstr=$outstr . $temps;  }   return $outstr;} function PassUnCode($s)//解密{  global $key;  $mstr="0123456789";  if (strlen($s)%2==1)  {    $function_ret="";    return $function_ret;  }   $m=0;  for ($I=1; $I<=strlen($s); $I=$I+2)  {    $t1=$s[$I-1];    $t2=$s[$I];    $j=strpos($mstr,$t1);    $k=strpos($mstr,$t2);    $n=$j+$k*strlen($mstr);    $Buff[$m]=$n;    $m=$m+1;  }   $k=count($key)+1;  $outstr="";  for ($I=0; $I<count($Buff); $I=$I+1)  {    $j=$I%$k;    $Buff[$I]=$Buff[$I] ^ $key[$j];    $outstr=$outstr . u2utf8($Buff[$I]);  }   return $outstr;}function utf8_unicode($c) {     switch(strlen($c))  {       case 1:         return ord($c);       case 2:         $n = (ord($c[0]) & 0x3f) << 6;         $n += ord($c[1]) & 0x3f;         return $n;       case 3:         $n = (ord($c[0]) & 0x1f) << 12;         $n += (ord($c[1]) & 0x3f) << 6;         $n += ord($c[2]) & 0x3f;         return $n;       case 4:         $n = (ord($c[0]) & 0x0f) << 18;         $n += (ord($c[1]) & 0x3f) << 12;         $n += (ord($c[2]) & 0x3f) << 6;         $n += ord($c[3]) & 0x3f;         return $n;     }  }  function u2utf8($c) {        $str="";        if ($c < 0x80) $str.= chr($c);        else if ($c < 0x800) {            $str.=chr(0xC0 | $c>>6);            $str.=chr(0x80 | $c & 0x3F);        } else if ($c < 0x10000) {            $str.=chr(0xE0 | $c>>12);            $str.=chr(0x80 | $c>>6 & 0x3F);            $str.=chr(0x80 | $c & 0x3F);        } else if ($c < 0x200000) {            $str.=chr(0xF0 | $c>>18);            $str.=chr(0x80 | $c>>12 & 0x3F);            $str.=chr(0x80 | $c>>6 & 0x3F);            $str.=chr(0x80 | $c & 0x3F);        }      return $str;    }  ?>
Copy after login


回复讨论(解决方案)

请懂PHP的朋友  来帮忙看看 小弟在此谢谢你们了!
 第39行 直接报错  :String offset cast occurred   
请指教下 
下面的解密过程结果是错误的

最后还是攻克了  自己搞定了 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!