Encryption method for PHP source code

Source: Internet
Author: User

Instance 1

The code is as follows Copy Code

<?php
Function Encode_file_contents ($filename) {
$type =strtolower (STRRCHR ($filename, '. '), 1);
if (' php ' = = $type && is_file ($filename) && is_writable ($filename)) {//If it is a PHP file and is writable, compress the encoding
$ Contents = file_get_contents ($filename);//Determine whether the file has been encoded for processing
$contents = Php_strip_whitespace ($filename);
//Remove PHP header and tail logo
$headerPos = strpos ($contents, ' <?php ');
$footerPos = Strrpos ($contents, '?> ');
$contents = substr ($contents, $headerPos +5, $footerPos-$headerPos);
$encode = Base64_encode (Gzdeflate ($contents));//start encoding
$encode = ' <?php '. N Eval (gzinflate (Base64_decode) ("."). $encode. "';")); Nn?> ";
Return file_put_contents ($filename, $encode);

}
return false;
}
//Call function
$filename = ' dam.php ';
Encode_file_contents ($filename);
Echo OK, encryption complete! "

Instance 2

The code is as follows Copy Code

<?php
function randabc ($length = "") {//return random string
$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
Return Str_shuffle ($STR);
}
$filename = ' dam.php ';
$T _k1=randabc ()/With secret key 1
$T _k2=randabc ()/With secret key 2
$vstr =file_get_contents ($filename);//files to be encrypted
$v 1=base64_encode ($VSTR);
$c =strtr ($v 1, $T _k1, $T _k2);//replace the corresponding character according to the key.
$c = $T _k1. $T _k2. $c;
$q 1= "o00o0o";
$q 2= "o0o000";
$q 3= "o0oo00";
$q 4= "oo0o00";
$q 5= "OO0000";
$q 6= "O00oo0";
$s = ' $ '. $q 6. ' =urldecode ("%6e1%7a%62%2f%6d%615%5c%76%740%6928%2d%70%78%75%71%79%2a6%6c%72%6b%64%679%5f%65%68%63%73%77%6f4%2b %6637%6A "); $ '. $q 1. ' =$ '. $q 6. ' {3}.$ '. $q 6. ' {6}.$ '. $q 6. ' {33}.$ '. $q 6. ' {30};$ '. $q 3. ' =$ '. $q 6. ' {33}.$ '. $q 6. ' {10}.$ '. $q 6. ' {24}.$ '. $q 6. ' {10}.$ '. $q 6. ' {24};$ '. $q 4. ' =$ '. $q 3. ' {0}.$ '. $q 6. ' {18}.$ '. $q 6. ' {3}.$ '. $q 3. ' {0}.$ '. $q 3. ' {1}.$ '. $q 6. ' {24};$ '. $q 5. ' =$ '. $q 6. ' {7}.$ '. $q 6. ' {13};$ '. $q 1. " =$ '. $q 6. ' {22}.$ '. $q 6. ' {36}.$ '. $q 6. ' {29}.$ '. $q 6. ' {26}.$ '. $q 6. ' {30}.$ '. $q 6. ' {32}.$ '. $q 6. ' {35}.$ '. $q 6. ' {26}.$ '. $q 6. ' {30};eval ($ '. $q 1. " ("'. Base64_encode (' $ ') $q 2." = "'. $c. '"; eval ('?> '. $ ') $q 1. ' ($ '. $q 3. " ($ '. $q 4. " ($ '. $q 2. ', $ '. $q 5. ' *2), $ '. $q 4. ' ($ '. $q 2. ', $ '. $q 5. ', $ '. $q 5. '), $ '. $q 4. ' ($ '. $q 2. ', 0,$ '. $q 5 "))); ';
$s = ' <?php
'. $s.
'
?> ';
echo "OK, encryption complete!" ";
Generate the encrypted PHP file
$FPP 1 = fopen (' dam.php ', ' W ');
Fwrite ($FPP 1, $s) or die (' Write file error ');
?>

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.