Fix for empty language descriptions with skip_english_translations
[openemr.git] / library / adodb / session / crypt.inc.php
blob61d145b69af76729c985ec73fffcbbb740249d5d
1 <?php
2 // Session Encryption by Ari Kuorikoski <ari.kuorikoski@finebyte.com>
3 class MD5Crypt{
4 function keyED($txt,$encrypt_key)
6 $encrypt_key = md5($encrypt_key);
7 $ctr=0;
8 $tmp = "";
9 for ($i=0;$i<strlen($txt);$i++){
10 if ($ctr==strlen($encrypt_key)) $ctr=0;
11 $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
12 $ctr++;
14 return $tmp;
17 function Encrypt($txt,$key)
19 srand((double)microtime()*1000000);
20 $encrypt_key = md5(rand(0,32000));
21 $ctr=0;
22 $tmp = "";
23 for ($i=0;$i<strlen($txt);$i++)
25 if ($ctr==strlen($encrypt_key)) $ctr=0;
26 $tmp.= substr($encrypt_key,$ctr,1) .
27 (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
28 $ctr++;
30 return base64_encode($this->keyED($tmp,$key));
33 function Decrypt($txt,$key)
35 $txt = $this->keyED(base64_decode($txt),$key);
36 $tmp = "";
37 for ($i=0;$i<strlen($txt);$i++){
38 $md5 = substr($txt,$i,1);
39 $i++;
40 $tmp.= (substr($txt,$i,1) ^ $md5);
42 return $tmp;
45 function RandPass()
47 $randomPassword = "";
48 srand((double)microtime()*1000000);
49 for($i=0;$i<8;$i++)
51 $randnumber = rand(48,120);
53 while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
55 $randnumber = rand(48,120);
58 $randomPassword .= chr($randnumber);
60 return $randomPassword;
66 class SHA1Crypt{
67 function keyED($txt,$encrypt_key)
70 $encrypt_key = sha1($encrypt_key);
71 $ctr=0;
72 $tmp = "";
74 for ($i=0;$i<strlen($txt);$i++){
75 if ($ctr==strlen($encrypt_key)) $ctr=0;
76 $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
77 $ctr++;
79 return $tmp;
83 function Encrypt($txt,$key)
86 srand((double)microtime()*1000000);
87 $encrypt_key = sha1(rand(0,32000));
88 $ctr=0;
89 $tmp = "";
91 for ($i=0;$i<strlen($txt);$i++)
95 if ($ctr==strlen($encrypt_key)) $ctr=0;
97 $tmp.= substr($encrypt_key,$ctr,1) .
99 (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
101 $ctr++;
105 return base64_encode($this->keyED($tmp,$key));
111 function Decrypt($txt,$key)
114 $txt = $this->keyED(base64_decode($txt),$key);
116 $tmp = "";
118 for ($i=0;$i<strlen($txt);$i++){
120 $sha1 = substr($txt,$i,1);
122 $i++;
124 $tmp.= (substr($txt,$i,1) ^ $sha1);
128 return $tmp;
133 function RandPass()
135 $randomPassword = "";
136 srand((double)microtime()*1000000);
138 for($i=0;$i<8;$i++)
141 $randnumber = rand(48,120);
143 while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
145 $randnumber = rand(48,120);
148 $randomPassword .= chr($randnumber);
151 return $randomPassword;