Home >Backend Development >PHP Tutorial >小白用php仿照js写的一个加密方法 就是有问题 求解答

小白用php仿照js写的一个加密方法 就是有问题 求解答

WBOY
WBOYOriginal
2016-06-02 11:33:56922browse

php加密javascrpit

原本的js是一段加密的方法
function checkform()
{
var dcode;
var dcode1;
var dcode2;

dcode=document.form1.pwd.value;
dcode1="";
dcode2=1275903582
dcode2=""+dcode2*137;
var tmpstr;
var dcodelen;
dcodelen=dcode.length;
for (i=1;itmpstr = dcode.substring(i-1,i);
dcode1=dcode1 + String.fromCharCode(tmpstr.charCodeAt(0)-i-dcode2.substring(i-1,i));
}

document.form1.pwd.value=dcode1;

}

这是我仿照写的php代码 但始终有错
//加密
function encryption($dcode){

<code>    $dcode1='';     $dcode2=1275903582;    $dcode2 = "".$dcode2 * 137;     $tmpstr='';      for ($i=1;$icharCodeAt($tmpstr, 0);             $num = $this->fromCharCode($tmpstr-$i-substr($dcode2,$i-1,1));             $dcode1=$dcode1 + $num;    }              $encryDcode=$dcode1;             print_r($encryDcode);             die();             return $encryDcode;     } </code>

function fromCharCode($codes) {
if (is_scalar($codes))
$codes= func_get_args();
$str= '';
foreach ($codes as $code)
$str.= chr($code);
return $str;
}

function charCodeAt($str, $index)
{
$char = mb_substr($str, $index, 1, 'UTF-8');

if (mb_check_encoding($char, 'UTF-8'))
{
$ret = mb_convert_encoding($char, 'UTF-32BE', 'UTF-8');
return hexdec(bin2hex($ret)); } else { return null;
}
}

Statement:
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