Home  >  Article  >  Backend Development  >  PHP encryption function Javascript/Js decryption function_PHP tutorial

PHP encryption function Javascript/Js decryption function_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:12:53903browse

In the following function code, "123456" is an encrypted key, which you can change at will.
php encryption, js decryption, seems meaningless, mainly because the key will be seen in js.
But it may be used in some places.

PHP encryption function

Copy code The code is as follows:

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:

Copy code The code is as follows:

<script> <br>function strencode(string) { <br>key = calcMD5('123456'); <br>string = Base64.decode(string); <br> len = key.length; <br> code = ''; <br> for (i = 0; i < string. length; i++) { <BR> k = i % len; <BR> code += String.fromCharCode(string.charCodeAt(i) ^ key.charCodeAt(k)); <BR> } <BR> return Base64.decode (code); <BR>}<BR>alert(strencode('PGZ6Cz40Z1JCWCYNRVtSDwsvfVsIexpcEFN0DU0OSQkXQUIPCQxnV1NLDA9SSw8PF1JhWxAHZ18FAGIncUFiFS5yWxAuClxUf15fXA==')); script> <br><br> </div> <p>PHP Encryption & JS Decryption 2<strong></strong> </p> <p></p> <div class="codetitle"><span style="CURSOR: pointer" onclick="doCopy('code15475')">Copy code<u></u> The code is as follows:</span></div> <div class="codebody" id="code15475"><?php<br>if(!function_exists(jm))<br> {<br> function jm($str){<br> $len = strlen($str);<br> for($i=0;$i<$len;$i++)<br> {<br> $ ascc=ord($str[$i]);<br> if($ascc<128)<br> {<br> $ascc=$ascc^7;<br> }<br> $res.=chr( $ascc);<br> }<br> return $res;<br> }//end function<br>}<br>echo "<script><br>xflag=true;<br>function xcount(xh ){<br> if(!xflag) return;<br> var xc="",xd=new Array(),xe="",xf=0;<br> for(i=0;i<xh. length;i++){<BR> xa=xh.charCodeAt(i);<BR> if(xa<128)xa=xa^7;<BR> xe+=String.fromCharCode(xa);<BR> if(xe .length>80){<br> xd[xf++]=xe;xe="";<br> }<br> }<br> xc=xd.join("")+xe;<br> document.write (xc);<br>}</script>";
$check_count = addslashes(jm("<script>alert('Test~~~');</script>"));
$check_count="";
echo "$check_count";
echo "";

http://www.bkjia.com/PHPjc/313591.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313591.htmlTechArticleIn the following function code, "123456" is an encrypted key, which you can change at will. PHP encryption and JS decryption seem meaningless. The main reason is that the key will be seen in JS. But in some places...
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