function Encrypt ($txt, $key) {$chars = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789-_."; $ikey = "-X6G6ZWM2G9G_VR0BO.POQ3KRIXSZ6RM"; $NH 1 = rand (0, 64); $NH 2 = rand (0, 64); $NH 3 = rand (0, 64); $ch 1 = $chars {$nh 1}; $ch 2 = $chars {$nh 2}; $ch 3 = $chars {$NH 3}; $nhnum = $nh 1 + $nh 2 + $nh 3; $knum = 0; $i = 0; while (Isset ($key {$i})) $knum + = Ord ($key {$i + +}); $mdKey = SUBSTR (MD5 (MD5 (MD5 ($key. $ch 1). $ch 2. $ikey). $ch 3), $nhnum% 8, $knum% 8 + 16); $txt = Base64_encode ($txt); $txt = str_replace (Array (' + ', '/', ' = '), array ('-', ' _ ', '. '), $txt); $tmp = "; $j = 0; $k = 0; $tlen = strlen ($txt); $klen = strlen ($mdKey); for ($i = 0; $i < $tlen; $i + +) {$k = $k = = $klen? 0: $k; $j = ($nhnum + strpos ($chars, $txt {$i}) + ord ($mdKey {$k + +})% 64; $tmp. = $chars {$j}; } $tmplen = strlen ($tmp); $tmp = Substr_replace ($tmp, $ch 3, $NH 2 + + $tmplen, 0); $tmp = Substr_replace ($tmp, $ch 2, $Nh1% + + $tmplen, 0); $tmp = Substr_replace ($tmp, $ch 1, $knum% + + $tmplen, 0); return $tmp;} function Decrypt ($txt, $key) {$chars = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789-_."; $ikey = "-X6G6ZWM2G9G_VR0BO.POQ3KRIXSZ6RM"; $knum = 0; $i = 0; $tlen = strlen ($txt); while (Isset ($key {$i})) $knum + = Ord ($key {$i + +}); $ch 1 = $txt {$knum% $tlen}; $nh 1 = Strpos ($chars, $ch 1); $txt = Substr_replace ($txt, ", $knum% $tlen--, 1); $ch 2 = $txt {$nh 1 $tlen}; $nh 2 = Strpos ($chars, $ch 2); $txt = Substr_replace ($txt, ", $nh 1 $tlen--, 1); $ch 3 = $txt {$NH 2 $tlen}; $nh 3 = Strpos ($chars, $ch 3); $txt = Substr_replace ($txt, ", $nh 2 $tlen--, 1); $nhnum = $nh 1 + $nh 2 + $nh 3; $mdKey = SUBSTR (MD5 (MD5 (MD5 ($key. $ch 1). $ch 2. $ikey). $ch 3), $nhnum% 8, $knum% 8 + 16); $tmp = "; $j = 0; $k = 0; $tlen = strlen ($txt); $klen = strlen ($mdKey); for ($i = 0; $i < $tlen; $i + +) {$k = $k = = $klen? 0: $k; $j = Strpos ($chars, $txt {$i})-$nhnum-ord ($mdKey {$k + +}); while ($j < 0) $j + = 64; $tmp. = $chars {$j}; } $tmp = Str_replace (Array ('-', ' _ ', '. '), Array (' + ', '/', ' = '), $tmp); Return Trim (Base64_decode ($tmp));}
PHP Plus Decrypt string