PHP加密函数Javascript/Js解密函数
以下函数代码中“123456”是个加密的key,自己可以随便改。
php加密,js解密,貌似没什么意义,主要是key在js中会被看到。
不过在某些地方可能会用到。
PHP加密函数
<?php
functionstrencode($string){
$string=base64_encode($string);
$key=md5("123456");
$len=strlen($key);
$code="";
for($i=0;$i<strlen($string);$i++){
$k=$i%$len;
$code.=$string[$i]^$key[$k];
}
returnbase64_encode($code);
}
echostrencode("abced你好我是你们定的点点滴滴asd@#$)()*&*&*");
?>
js解密函数:
<script>
functionstrencode(string){
key=calcMD5("123456");
string=Base64.decode(string);
len=key.length;
code="";
for(i=0;i<string.length;i++){
k=i%len;
code+=String.fromCharCode(string.charCodeAt(i)^key.charCodeAt(k));
}
returnBase64.decode(code);
}
alert(strencode("PGZ6Cz40Z1JCWCYNRVtSDwsvfVsIexpcEFN0DU0OSQkXQUIPCQxnV1NLDA9SSw8PF1JhWxAHZ18FAGIncUFiFS5yWxAuClxUf15fXA=="));
</script>
PHP加密&JS解密2
<?php
if(!function_exists(jm))
{
functionjm($str){
$len=strlen($str);
for($i=0;$i<$len;$i++)
{
$ascc=ord($str[$i]);
if($ascc<128)
{
$ascc=$ascc^7;
}
$res.=chr($ascc);
}
return$res;
}//endfunction
}
echo"<script>
xflag=true;
functionxcount(xh){
if(!xflag)return;
varxc=\"\",xd=newArray(),xe=\"\",xf=0;
for(i=0;i<xh.length;i++){
xa=xh.charCodeAt(i);
if(xa<128)xa=xa^7;
xe+=String.fromCharCode(xa);
if(xe.length>80){
xd[xf++]=xe;xe=\"\";
}
}
xc=xd.join(\"\")+xe;
document.write(xc);
}</script>";
$check_count=addslashes(jm("<script>alert("测试咯~~~");</script>"));
$check_count="<SCRIPTLANGUAGE=\"JavaScript\">xcount(\"$check_count\");</SCRIPT>";
echo"$check_count";
echo"<!--countended-->";
相关文章