Loading Please wait...

zCryptDrv_xor_intermediate Class Reference
[Zigmoyd Encryption System.]

XOR adapter (Intermediate) for Zigmoyd Encryption System. More...

Inheritance diagram for zCryptDrv_xor_intermediate:

Inheritance graph
[legend]
Collaboration diagram for zCryptDrv_xor_intermediate:

Collaboration graph
[legend]

Public Member Functions

 zCryptDrv_xor_intermediate ()
 __construct ()
 blockise ($str)
 Blockise a String into Block Size.
 dblockise ($str)
 Deblockise a String.
 psubstr ($str, $start, $len)
 Unknown Operation.
 get_block ($str, $i)
 Get Specified Block of a string supplied.
 x_enc ($string, $key)
 Unknown Operation.
 x_dcd ($string, $key)
 Unknown Operation.
 enc ($str, $key)
 encodes
 dcd ($str, $key)
 decodes
 encode ($str, $key, $mode=ENC_BIN)
 Encodes using enc().
 decode ($str, $key, $mode=ENC_BIN)
 Decodes using dcd().
 dec_decode ($salted)
 Decodes a Numarically encoded string.
 dec_encode ($salt)
 Encodes a string into 0-9 Numbers and returns that numarical string.

Data Fields

 $val

Detailed Description

XOR adapter (Intermediate) for Zigmoyd Encryption System.

can be used when mcrypt is not available

Definition at line 30 of file xor.php.


Constructor & Destructor Documentation

zCryptDrv_xor_intermediate::__construct (  ) 

Reimplemented from zCore.

Reimplemented in zCryptDrv_xor.

Definition at line 36 of file xor.php.

Referenced by zCryptDrv_xor_intermediate().

00036                         {
00037     parent::__construct();
00038     if(!defined('BLOCK_SIZE')){define('BLOCK_SIZE', 4);}
00039     if(!defined('BLOCK_JUNK')){define('BLOCK_JUNK', 5);}
00040     if(!defined('ENC_BIN')){define('ENC_BIN', true);}
00041     if(!defined('ENC_DEC')){define('ENC_DEC', false);}
00042     $this->val = array(' ', '+', '_', '*', '&', ':', '-', '@', '=', '%');
00043   }


Member Function Documentation

zCryptDrv_xor_intermediate::zCryptDrv_xor_intermediate (  ) 

Definition at line 33 of file xor.php.

References __construct().

00033                                        {
00034     $this->__construct();
00035   }

Here is the call graph for this function:

zCryptDrv_xor_intermediate::blockise ( str  ) 

Blockise a String into Block Size.

If a string is less than Block size Fills it with Junks

Parameters:
$str string
Returns:
string

Definition at line 51 of file xor.php.

Referenced by enc().

00051                          {
00052     if(strlen($str) >= BLOCK_SIZE*2){return $str;}
00053     while(strlen($str) < BLOCK_SIZE*2){
00054       $str .= chr(BLOCK_JUNK);
00055     }
00056     return $str;
00057   }

zCryptDrv_xor_intermediate::dblockise ( str  ) 

Deblockise a String.

reverse operatin of zCryptDrv_xor_intermediate::blockise()

Parameters:
$str string
Returns:
string

Definition at line 65 of file xor.php.

Referenced by dcd().

00065                           {
00066     for($i=strlen($str)-1;$i>=strlen($str)-1-8;$i--){
00067       if(isset($str[$i]) && $str[$i] != chr(BLOCK_JUNK)){break;}
00068       $str = substr($str, 0, $i);
00069     }
00070     return $str;
00071   }

zCryptDrv_xor_intermediate::psubstr ( str,
start,
len 
)

Unknown Operation.

Parameters:
$str string
$start int
$len int
Returns:
string

Definition at line 80 of file xor.php.

Referenced by dcd(), enc(), and get_block().

00080                                       {
00081     if($start < 0){$tmp = "";return $tmp;};
00082     return substr($str, $start, $len);
00083   }

zCryptDrv_xor_intermediate::get_block ( str,
i 
)

Get Specified Block of a string supplied.

Parameters:
$str string
$i int
Returns:
string

Definition at line 91 of file xor.php.

References psubstr().

Referenced by dcd(), and enc().

00091 {return $this->psubstr($str, $i, BLOCK_SIZE);}

Here is the call graph for this function:

zCryptDrv_xor_intermediate::x_enc ( string,
key 
)

Unknown Operation.

Parameters:
$string string
$key string
Returns:
string

Definition at line 99 of file xor.php.

Referenced by enc(), and x_dcd().

00099                                {
00100     for($i=0; $i<=strlen($string)-1; $i++){
00101       for($j=0; $j<=strlen($key)-1; $j++){
00102         $string[$i] = $string[$i]^$key[$j];
00103       }
00104       if($i != 0 && $i != strlen($string)-1){
00105         $string[$i] = $string[$i]^$string[$i-1]^$string[$i+1];
00106       }
00107     }
00108    return $string;
00109   }

zCryptDrv_xor_intermediate::x_dcd ( string,
key 
)

Unknown Operation.

Parameters:
$string string
$key string
Returns:
string

Definition at line 117 of file xor.php.

References x_enc().

Referenced by dcd().

00117                                {
00118     for($i=strlen($string)-1; $i>=0; $i--){
00119       if($i == 0 || $i == strlen($string)-1){
00120         for($j=0; $j<=strlen($key)-1; $j++){
00121           $string[$i] = $string[$i]^$key[$j];
00122         }
00123       }else{
00124         $string[$i] = $this->x_enc($string[$i], $key)^$string[$i-1]^$string[$i+1];
00125       }
00126     }
00127     return $string;
00128   }

Here is the call graph for this function:

zCryptDrv_xor_intermediate::enc ( str,
key 
)

encodes

Parameters:
$str string
$key string
Returns:
string

Definition at line 136 of file xor.php.

References blockise(), get_block(), psubstr(), and x_enc().

Referenced by encode().

00136                           {
00137     $str = base64_encode($this->blockise($str));
00138     for($i=0;$i<=strlen($str)-1;$i+=BLOCK_SIZE){
00139       if($i == 0 || $i == (strlen($str)-BLOCK_SIZE)){
00140         $repl = $this->x_enc($this->psubstr($str, $i, BLOCK_SIZE), $key);
00141         $str = substr_replace($str, $repl, $i, BLOCK_SIZE);
00142       }else{
00143         if($i == BLOCK_SIZE){
00144           $b = $this->x_enc($this->get_block($str, $i), $key);
00145         }
00146         $repl = $this->x_enc($this->get_block($str, $i+BLOCK_SIZE), $this->get_block($str, $i-BLOCK_SIZE));
00147         $str = substr_replace($str, $repl, $i, BLOCK_SIZE);
00148       }
00149     }
00150     $str .= $b;
00151     return $str;
00152   }

Here is the call graph for this function:

zCryptDrv_xor_intermediate::dcd ( str,
key 
)

decodes

Parameters:
$str string
$key string
Returns:
string

Definition at line 160 of file xor.php.

References dblockise(), get_block(), psubstr(), and x_dcd().

Referenced by decode().

00160                           {
00161     $b = $this->x_dcd($this->get_block($str, strlen($str)-BLOCK_SIZE), $key);
00162     $str = substr($str, 0, strlen($str)-BLOCK_SIZE);
00163     for($i=strlen($str)-BLOCK_SIZE;$i>=0;$i-=BLOCK_SIZE){
00164       if($i == 0 || $i == (strlen($str)-BLOCK_SIZE)){
00165         $repl = $this->x_dcd($this->psubstr($str, $i, BLOCK_SIZE), $key);
00166         $str = substr_replace($str, $repl, $i, BLOCK_SIZE);
00167       }else{
00168         if($i == BLOCK_SIZE){
00169           $str = substr_replace($str, $b, $i, BLOCK_SIZE);
00170         }else{
00171           $repl = $this->x_dcd($this->psubstr($str, $i-BLOCK_SIZE, BLOCK_SIZE), $this->psubstr($str, $i-(BLOCK_SIZE*2), BLOCK_SIZE));
00172           $str = substr_replace($str, $repl, $i, BLOCK_SIZE);
00173         }
00174       }
00175     }
00176     return $this->dblockise(base64_decode($str));
00177   }

Here is the call graph for this function:

zCryptDrv_xor_intermediate::encode ( str,
key,
mode = ENC_BIN 
)

Encodes using enc().

If $mode is ENC_BIN encodes in binary mode else if mode set to ENC_DEC encodes in decimal mode

Parameters:
$str string string to Encode
$key string key whith which to encode
$mode int mode in binary mode or in decimal defaults to ENC_BIN however you can also use ENC_DEC
Returns:
string

Definition at line 187 of file xor.php.

References dec_encode(), enc(), and perror().

Referenced by zCryptDrv_xor::encrypt().

00187                                               {
00188     if($mode == ENC_BIN){
00189       return $this->enc($this->enc($str, $key), md5($key));
00190     }elseif($mode == ENC_DEC){
00191       return $this->dec_encode($this->enc($this->enc($str, $key), md5($key)));
00192     }
00193     perror("Invalid MODE SPecified");
00194     return false;
00195   }

Here is the call graph for this function:

zCryptDrv_xor_intermediate::decode ( str,
key,
mode = ENC_BIN 
)

Decodes using dcd().

If $mode is ENC_BIN encodes in binary mode else if mode set to ENC_DEC encodes in decimal mode

Parameters:
$str string string to decode
$key string key whith which to decode
$mode int mode in binary mode or in decimal defaults to ENC_BIN however you can also use ENC_DEC
Returns:
string

Definition at line 205 of file xor.php.

References dcd(), dec_decode(), and perror().

Referenced by zCryptDrv_xor::decrypt().

00205                                               {
00206     if($mode == ENC_BIN){
00207       return $this->dcd($this->dcd($str, md5($key)), $key);
00208     }elseif($mode == ENC_DEC){
00209       return $this->dcd($this->dcd($this->dec_decode($str), md5($key)),$key);
00210     }
00211     perror("Invalid MODE SPecified");
00212     return false;
00213   }

Here is the call graph for this function:

zCryptDrv_xor_intermediate::dec_decode ( salted  ) 

Decodes a Numarically encoded string.

Parameters:
$salted string Encoded string to decode
Returns:
string

Definition at line 220 of file xor.php.

References $val.

Referenced by decode().

00220                               {
00221       $key = array(0,1,2,3,4,5,6,7,8,9);$ret = '';
00222       $val = $this->val;
00223       $str = str_replace($val, $key, $salted);
00224       for($i=0;$i<=strlen($str)-1;$i+=3){
00225         $current_group = $str[$i].$str[$i+1].$str[$i+2];
00226         $tmp_int = (int)($current_group);
00227         $ret .= chr($tmp_int);
00228       }
00229       return base64_decode($ret);
00230   }

zCryptDrv_xor_intermediate::dec_encode ( salt  ) 

Encodes a string into 0-9 Numbers and returns that numarical string.

Parameters:
$salt String to encode
Returns:
string

Definition at line 237 of file xor.php.

References $val.

Referenced by encode().

00237                             {
00238       $str = base64_encode($salt);$tmp = '';
00239       for($i=0;$i<=strlen($str)-1;$i++){
00240         if(ord($str[$i]) < 100){
00241           if(ord($str[$i]) > 0 && ord($str[$i]) < 10){
00242             $num = "00".ord($str[$i]);
00243           }
00244           elseif(ord($str[$i]) >= 10 && ord($str[$i]) < 100){
00245             $num = "0".ord($str[$i]);
00246           }
00247         }
00248         else{
00249           $num = ord($str[$i]);
00250         }
00251         $tmp .= $num;
00252       }
00253      $key = array(0,1,2,3,4,5,6,7,8,9);
00254      $val = $this->val;
00255      $ret = str_replace($key, $val, $tmp);
00256      return $ret;
00257     }


Field Documentation

zCryptDrv_xor_intermediate::$val

Definition at line 31 of file xor.php.

Referenced by zCryptDrv_xor::__construct(), dec_decode(), and dec_encode().


The documentation for this class was generated from the following file:

Generated on Mon Oct 27 23:53:45 2008 for zigmoyd.kdevelop by doxygen 1.5.6