PHP uses XOR or implemented encryption to decrypt instance _php instance

Source: Internet
Author: User

if a=b ^ C; then B=a ^ C (^ is the meaning of XOR), PHP in the processing of different or character characters first convert the characters into binary ASCII values, or, to obtain the results after the ASCII value into the character, the principle of a direct paste implementation of the code:

Copy Code code as follows:

Echo ' <meta charset= ' utf-8 ' > ';
$str = ' World, hello ';
function Jiami ($STR, $key) {
$key =md5 ($key);
$k =md5 (rand (0,100));//equivalent to dynamic key
$k =substr ($k, 0, 3);
$tmp = "";
for ($i =0; $i <strlen ($STR); $i + +) {
$tmp. =substr ($str, $i, 1) ^ substr ($key, $i, 1);
}
Return Base64_encode ($k. $tmp);
}
function Jiemi ($STR, $key) {
$len =strlen ($STR);
$key =md5 ($key);
$str =base64_decode ($STR);
$str =substr ($STR, 3, $len-3);
$tmp = "";
for ($i =0; $i <strlen ($STR); $i + +) {
$tmp. =substr ($str, $i, 1) ^ substr ($key, $i, 1);
}
return $tmp;
}
$key = ' CC ';
$jh =jiami ($str, $key);
Echo ' Before encryption: '. $str. ' <br> ';
Echo ' encrypted: '. $jh. ' <br> ';
Echo ' after decryption: '. Jiemi ($jh, $key). ' <br> ';

There is a chance in the perfect, this function is to achieve a simple encryption and decryption

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.