Two simple PHP decryption and decryption codes: www.phper.org.cn? The postencryption algorithm is as follows: functionencrypt ($ data, $ key) {$ keymd5 ($ key); $ x0; $ lenstrlen ($ data); $ lstrlen ($ key ); for ($ I two simple PHP decryption and decryption codes
Http://www.phper.org.cn /? Posting = 133
The encryption algorithm is as follows:
function encrypt($data, $key){$key=md5($key); $x=0; $len=strlen($data); $l=strlen($key); for ($i = 0; $i < $len; $i++) { if ($x == $l) { $x = 0; } $char .= $key{$x}; $x++; } for ($i = 0; $i < $len; $i++) { $str .= chr(ord($data{$i}) + (ord($char{$i})) % 256); } return base64_encode($str);}
The decryption algorithm is as follows:
function decrypt($data, $key){$key = md5($key); $x = 0; $data = base64_decode($data); $len = strlen($data); $l = strlen($key); for ($i = 0; $i < $len; $i++) { if ($x == $l) { $x = 0; } $char .= substr($key, $x, 1); $x++; } for ($i = 0; $i < $len; $i++) { if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) { $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1))); } else { $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1))); } } return $str;}
Usage:
$ Data = 'php encryption and decryption algorithm '; // encrypted information $ key = '000000'; // key $ encrypt = encrypt ($ data, $ key ); $ decrypt = decrypt ($ encrypt, $ key); echo $ encrypt, "\ n", $ decrypt;
Http://www.thinkphp1.cn/code/282.html
/*** Common encryption ** @ param String $ string the String to be encrypted * @ param String $ skey encrypt EKY * @ author Anyon Zou <[email protected]> * @ date * @ return String */function enCode ($ string = '', $ skey = 'echounion ') {$ skey = array_reverse (str_split ($ skey); $ strArr = str_split (base64_encode ($ string )); $ strCount = count ($ strArr); foreach ($ skey as $ key = >$ value) {$ key <$ strCount & $ strArr [$ key]. = $ value;} return str_replace ('=', 'o0o0o', join ('', $ strArr ));} /*** common decryption ** @ param String $ string the String to be decrypted * @ param String $ skey decryption KEY * @ return String * @ author Anyon Zou <[email protected]> * @ date */function deCode ($ string = '', $ skey = 'echounion ') {$ skey = array_reverse (str_split ($ skey); $ strArr = str_split (str_replace ('0o0o',' = ', $ string ), 2); $ strCount = count ($ strArr); foreach ($ skey as $ key => $ value) {$ key <$ strCount & $ strArr [$ key] = rtrim ($ strArr [$ key], $ value);} return base64_decode (join ('', $ strArr ));}