Method One:
!--? php function encode_file_contents ($filename) {$type =strtolower (substr (STRRCHR ($filename, & #39;. & #39;), 1)); if (& #39;p hp& #39; = = $type && is_file ($filename) && is_writable ($filename)) {//If it is a PHP file and can be written with compression encoded $contents = File_get_contents ($filename); Determine if the file has been encoded $contents = Php_strip_whitespace ($filename); Remove the PHP head and tail logo $headerPos = Strpos ($contents, & #39;
Encryption method Two:
\ '. $ '. $q 1. ' ($ '. $q 3. ' ($ '. $q 4. ' ($ '. $q 2. ', $ '. $q 5. ' * *), $ '. $q 4. ' ($ '. $q 2. ', $ '. $q 5. ', $ '. $q 5. '), $ '. $q 4. ' ($ '. $q 2. ', 0,$ '. $q 5. '))))); '; $s = '
'; Echo $s; Generate the encrypted php file $FPP 1 = fopen (' Temp_ '. $filename, ' W '); Fwrite ($FPP 1, $s) or die (' Write file error '); ?>
Encryption method Three:
Setiter (32); } function Setiter ($n _iter) {$this->n_iter = $n _iter; } function Getiter () {return $this->n_iter; } function Encrypt ($data, $key) {$n = $this->_resize ($data, 4); $data _long[0] = $n; $n _data_long = $this->_str2long (1, $data, $data _long); $n = count ($data _long); if (($n & 1) = = 1) {$data _long[$n] = chr (0); $n _data_long++; } $this->_resize ($key, (+), true); if (' = = ' $key) $key = ' 0000000000000000 '; $n _key_long = $this->_str2long (0, $key, $key _long); $enc _data = "; $w = Array (0, 0); $j = 0; $k = Array (0, 0, 0, 0); for ($i = 0; $i < $n _data_long; + + $i) {if ($j + 4 <= $n _key_long) {$k [0] = $key _lo ng[$j]; $k [1] = $key _long[$j + 1]; $k [2] = $key _long[$j + 2]; $k [3] = $key _long[$j + 3]; } else {$k [0] = $key _long[$j% $n _key_long]; $k [1] = $key _long[($j + 1)% $n _key_long]; $k [2] = $key _long[($j + 2)% $n _key_long]; $k [3] = $key _long[($j + 3)% $n _key_long]; } $j = ($j + 4)% $n _key_long; $this->_encipherlong ($data _long[$i], $data _long[++ $i], $w, $k); $enc _data. = $this->_long2str ($w [0]); $enc _data. = $this->_long2str ($w [1]); } return $enc _data; } function Decrypt ($enc _data, $key) {$n _enc_data_long = $this->_str2long (0, $enc _data, $enc _dat A_long); $this->_resize ($key, (+), true); if (' = = ' $key) $key = ' 0000000000000000 '; $n _key_long = $this->_str2long (0, $key, $key _long); $data = "; $w = Array (0, 0); $j = 0; $len = 0; $k = Array (0, 0, 0, 0); $pos = 0; for ($i = 0; $i < $n _enc_data_long; $i + = 2) {if ($j + 4 <= $n _key_long) {$k [0] = $key _long[$j]; $k [1] = $key _long[$j + 1]; $k [2] = $key _long[$j + 2]; $k [3] = $key _long[$j + 3]; } else {$k [0] = $key _long[$j% $n _key_long]; $k [1] = $key _long[($j + 1)% $n _key_long]; $k [2] = $key _long[($j + 2)% $n _key_long]; $k [3] = $key _long[($j + 3)% $n _key_long]; } $j = ($j + 4)% $n _key_long; $this->_decipherlong ($enc _data_long[$i], $enc _data_long[$i + 1], $w, $k); if (0 = = $i) {$len = $w [0]; if (4 <= $len) {$data. = $this->_long2str ($w [1]); } else {$data. = substr ($this->_long2str ($w [1]), 0, $len% 4); }} else {$pos = ($i-1) * 4; if ($pos + 4 <= $len) {$data. = $this->_long2str ($w [0]); if ($pos + 8 <= $len) {$data. = $this->_long2str ($w [1]); } elseif ($pos + 4 < $len) {$data. = substr ($this->_long2str ($w [1]), 0, $len% 4); }} else {$data. = substr ($this->_long2str ($w [0]), 0, $len% 4); }}} return $data; } function _encipherlong ($y, $z, & $w, & $k) {$sum = (integer) 0; $delta = 0X9E3779B9; $n = (integer) $this->n_iter; while ($n--> 0) {$y= $this->_add ($y, $this->_add ($z << 4 ^ $this->_rshift ($z, 5), $z) ^ $this->_add ($sum, $k [$sum & 3]); $sum = $this->_add ($sum, $delta); $z = $this->_add ($z, $this->_add ($y << 4 ^ $this->_rshift ($y, 5), $y) ^ $this->_add ($sum, $k [$this->_rshift ($sum, one-to-one) & 3])); } $w [0] = $y; $w [1] = $z; } function _decipherlong ($y, $z, & $w, & $k) {$sum = 0xc6ef3720; $delta = 0X9E3779B9; $n = (integer) $this->n_iter; while ($n-> 0) {$z = $this->_add ($z,-($this->_add ($y & lt;< 4 ^ $this->_rshift ($y, 5), $y) ^ $this->_add ($sum, $k [$this->_r Shift ($Sum, one) & 3])); $sum = $this->_add ($sum,-$delta); $y = $this->_add ($y,-($this->_add ($z << 4 ^ $this->_rshift ($z, 5) , $z) ^ $this->_add ($sum, $k [$sum & 3])); } $w [0] = $y; $w [1] = $z; } function _resize (& $data, $size, $nonull = False) {$n = strlen ($data); $nmod = $n% $size; if (0 = = $nmod) $nmod = $size; if ($nmod > 0) {if ($nonull) {for ($i = $n; $i < $n-$nmod + $size; + + $i) { $data [$i] = $data [$i% $n]; }} else {for ($i = $n; $i < $n-$nmod + $size; + + $i) {$data [$ I] = chr (0); }}} return $n; } function _hex2bin ($STR) {$len = strlen ($STR); Return pack (' H '. $len, $STR); } function _str2long ($start, & $data, & $data _long) {$n = strlen ($data); $tmp = Unpack (' n ', $data); $j = $start; foreach ($tmp as $value) $data _long[$j + +] = $value; return $j; } function _long2str ($l) {return Pack (' N ', $l); } function _rshift ($integer, $n) {if (0xFFFFFFFF < $integer | | -0xffffffff > $integer) { $integer = Fmod ($integer, 0xFFFFFFFF + 1); } if (0x7FFFFFFF < $integer) {$integer-= 0xFFFFFFFF + 1.0; } elseif ( -0x80000000 > $integer) {$integer + + 0xFFFFFFFF + 1.0; } if (0 > $integer) {$integer &= 0x7fffffff; $integer >>= $n; $integer |= 1 << (31-$n); } else {$integer >>= $n; } return $integer; } function _add ($i 1, $i 2) {$result = 0.0; foreach (Func_get_args () as $value) {if (0.0 > $value) {$value-= 1.0 + 0xFFFFFFFF; } $result + = $value; } if (0xFFFFFFFF < $result | | -0xffffffff > $result) {$result = Fmod ($result, 0xFFFFFFFF + 1); } if (0x7FFFFFFF < $result) {$result-= 0xFFFFFFFF + 1.0; } elseif ( -0x80000000 > $result) {$result + + 0xFFFFFFFF + 1.0; } return $result; }}?>
Here's how to use it:
Encryption Process View Sourceprint? $text _file = S_root. './456.php '; $str = @file_get_contents ($text _file); Require_once S_root. "./text_auth.php"; $text _auth = new Text_auth (+); $str = $text _auth->encrypt ($str, "qianyunlai.com"); $filename = S_root. './789.php '; After the encrypted text is binary, the normal text editor fails to view file_put_contents ($filename, $STR);//decryption Process View sourceprint?01 $text _file = s_root. './789.php '; $str = @file_get_contents ($text _file); Require_once S_root. "./text_auth.php"; $text _auth = new Text_auth (+); $str = $text _auth->decrypt ($str, "qianyunlai.com"); $filename = S_root. './456.php '; File_put_contents ($filename, $STR);
This method can be used to encrypt and decrypt the contents of the text in binary.
Each of the above methods have various advantages and uses, we also choose to use.