Adodb Dokumentation  V5.14 8 Sept 2011
session/crypt.inc.php
00001 <?php
00002 //       Session Encryption by Ari Kuorikoski <ari.kuorikoski@finebyte.com>
00003 class MD5Crypt{
00004                 function keyED($txt,$encrypt_key)
00005                 {
00006                                 $encrypt_key = md5($encrypt_key);
00007                                 $ctr=0;
00008                                 $tmp = "";
00009                                 for ($i=0;$i<strlen($txt);$i++){
00010                                                 if ($ctr==strlen($encrypt_key)) $ctr=0;
00011                                                 $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
00012                                                 $ctr++;
00013                                 }
00014                                 return $tmp;
00015                 }
00016 
00017                 function Encrypt($txt,$key)
00018                 {
00019                                 srand((double)microtime()*1000000);
00020                                 $encrypt_key = md5(rand(0,32000));
00021                                 $ctr=0;
00022                                 $tmp = "";
00023                                 for ($i=0;$i<strlen($txt);$i++)
00024                                 {
00025                                 if ($ctr==strlen($encrypt_key)) $ctr=0;
00026                                 $tmp.= substr($encrypt_key,$ctr,1) .
00027                                 (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
00028                                 $ctr++;
00029                                 }
00030                                 return base64_encode($this->keyED($tmp,$key));
00031                 }
00032 
00033                 function Decrypt($txt,$key)
00034                 {
00035                                 $txt = $this->keyED(base64_decode($txt),$key);
00036                                 $tmp = "";
00037                                 for ($i=0;$i<strlen($txt);$i++){
00038                                                 $md5 = substr($txt,$i,1);
00039                                                 $i++;
00040                                                 $tmp.= (substr($txt,$i,1) ^ $md5);
00041                                 }
00042                                 return $tmp;
00043                 }
00044 
00045                 function RandPass()
00046                 {
00047                                 $randomPassword = "";
00048                                 srand((double)microtime()*1000000);
00049                                 for($i=0;$i<8;$i++)
00050                                 {
00051                                                 $randnumber = rand(48,120);
00052 
00053                                                 while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
00054                                                 {
00055                                                                 $randnumber = rand(48,120);
00056                                                 }
00057 
00058                                                 $randomPassword .= chr($randnumber);
00059                                 }
00060                                 return $randomPassword;
00061                 }
00062 
00063 }
00064 
00065 
00066 class SHA1Crypt{
00067                 function keyED($txt,$encrypt_key)
00068                 {
00069 
00070                                 $encrypt_key = sha1($encrypt_key);
00071                                 $ctr=0;
00072                                 $tmp = "";
00073 
00074                                 for ($i=0;$i<strlen($txt);$i++){
00075                                                 if ($ctr==strlen($encrypt_key)) $ctr=0;
00076                                                 $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
00077                                                 $ctr++;
00078                                 }
00079                                 return $tmp;
00080 
00081                 }
00082 
00083                 function Encrypt($txt,$key)
00084                 {
00085 
00086                                 srand((double)microtime()*1000000);
00087                                 $encrypt_key = sha1(rand(0,32000));
00088                                 $ctr=0;
00089                                 $tmp = "";
00090 
00091                                 for ($i=0;$i<strlen($txt);$i++)
00092 
00093                                 {
00094 
00095                                 if ($ctr==strlen($encrypt_key)) $ctr=0;
00096 
00097                                 $tmp.= substr($encrypt_key,$ctr,1) .
00098 
00099                                 (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
00100 
00101                                 $ctr++;
00102 
00103                                 }
00104 
00105                                 return base64_encode($this->keyED($tmp,$key));
00106 
00107                 }
00108 
00109 
00110 
00111                 function Decrypt($txt,$key)
00112                 {
00113 
00114                                 $txt = $this->keyED(base64_decode($txt),$key);
00115 
00116                                 $tmp = "";
00117 
00118                                 for ($i=0;$i<strlen($txt);$i++){
00119 
00120                                                 $sha1 = substr($txt,$i,1);
00121 
00122                                                 $i++;
00123 
00124                                                 $tmp.= (substr($txt,$i,1) ^ $sha1);
00125 
00126                                 }
00127 
00128                                 return $tmp;
00129                 }
00130 
00131 
00132 
00133                 function RandPass()
00134                 {
00135                                 $randomPassword = "";
00136                                 srand((double)microtime()*1000000);
00137 
00138                                 for($i=0;$i<8;$i++)
00139                                 {
00140 
00141                                                 $randnumber = rand(48,120);
00142 
00143                                                 while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
00144                                                 {
00145                                                                 $randnumber = rand(48,120);
00146                                                 }
00147 
00148                                                 $randomPassword .= chr($randnumber);
00149                                 }
00150 
00151                                 return $randomPassword;
00152 
00153                 }
00154 
00155 
00156 
00157 }
00158 ?>