PHP encryption function Javascript and Js decryption function
- 2020-09-28 08:49:21
- OfStack
In the following function code "123456" is an encrypted key, which you can change at will.
php encryption, js decryption, seems to make no sense, mainly key will be seen in js.
But it might be used in some places.
PHP encryption function
<?php
function strencode($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];
}
return base64_encode ( $code );
}
echo strencode ( 'abced Hello, I am your order asd@#$)()*&*&*' );
?>
js decryption function:
<script>
function strencode(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));
}
return Base64.decode(code);
}
alert(strencode('PGZ6Cz40Z1JCWCYNRVtSDwsvfVsIexpcEFN0DU0OSQkXQUIPCQxnV1NLDA9SSw8PF1JhWxAHZ18FAGIncUFiFS5yWxAuClxUf15fXA=='));
</script>
PHP encryption & JS decryption 2
<?php
if(!function_exists(jm))
{
function jm($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;
}//end function
}
echo "<script>
xflag=true;
function xcount(xh){
if(!xflag) return;
var xc=\"\",xd=new Array(),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(' The test! ~~~');</script>"));
$check_count="<SCRIPT LANGUAGE=\"JavaScript\">xcount(\"$check_count\");</SCRIPT>";
echo "$check_count";
echo "<!-- count ended -->";