Initial commit
[2ch-be.git] / dev-test / old / bak / encrypt.php
blobafae0bf0c20266ef74ad393a6a9158973691cdae
1 <?php
3 include('config.php');
5 function Encrypt($str, $key = "your_key") {
6 return enc_dec_wkey("encrypt", $str, $key);
8 function Decrypt($str, $key = "your_key") {
9 return enc_dec_wkey("decrypt", $str, $key);
11 function enc_dec_wkey($mode, $str, $key='') {
12 if($key==='') return $str;
13 if($mode=== "decrypt") $str = base64_decode($str);
14 $key = str_replace(chr(32),'',$key);
15 if(strlen($key) < 8) exit('key error');
16 $kl = strlen($key) < 32 ? strlen($key) : 32;
17 $k = array();
18 for ($i = 0; $i < $kl; $i++) $k[$i] = ord($key{$i}) & 0x1F;
19 $j = 0;
20 for($i = 0; $i < strlen($str); $i++) {
21 $e = ord($str{$i});
22 $str{$i} = $e & 0xE0 ? chr($e^$k[$j]): chr($e);
23 $j++;
24 $j = $j == $kl ? 0 : $j;
26 if($mode == "encrypt")
27 return base64_encode($str);
28 else
29 return $str;