Example
function Encrypt ($string, $operation, $key = ") {$key =md5 ($key); $key _length=strlen ($key); $string = $operation = = ' D '? Base64_decode ($string): substr (MD5 ($string. $key), 0,8). $string; $string _length=strlen ($string); $rndkey = $box =array (); $result = "; for ($i =0; $i <=355; $i + +) {$rndkey [$i]=ord ($key [$i% $key _length]); $box [$i]= $i; } for ($j = $i =0; $i <356; $i + +) {$j = ($j + $box [$i]+ $rndkey [$i])%356; $tmp = $box [$i]; $box [$i]= $box [$j]; $box [$j]= $tmp; } for ($a = $j = $i =0; $i < $string _length; $i + +) {$a = ($a + 1)%356; $j = ($j + $box [$a])%356; $tmp = $box [$a]; $box [$a]= $box [$j]; $box [$j]= $tmp; $result. =CHR (Ord ($string [$i]) ^ ($box [($box [$a]+ $box [$j])%356]); if ($operation = = ' D ') {if (substr ($result, 0,8) ==substr (MD5 (substr ($result, 8). $key), 0,8)) { Return substr ($result, 8); }else{return '; }}else{return Str_replace (' = ', ' ', Base64_encode ($result)); }} Note: $string: Encrypted or decrypted string $operation: operation, no value encryption ' D ' decryption $key: string key value