Esempio n. 1
0
 /**
  * Make a run of rotation
  *
  * @param null $rotation
  * @return $this
  */
 public function rotate($rotation = null)
 {
     if (is_null($rotation)) {
         $rotation = $this->rotation;
     }
     $cipher = $this->getSubstitutions();
     $this->setSubstitutions(array(Helper::rotate($cipher[0], $rotation)));
     return $this;
 }
Esempio n. 2
0
            <blockquote><?php 
echo $str;
?>
</blockquote>

            <p>The plain text key used is: "<code><?php 
echo $plain;
?>
</code>"</p>

            <h3><code>SubstitutionCipher\Simple</code></h3>

            <pre>
<?php 
echo "> plain text key is : '{$plain}'" . PHP_EOL;
$key = \Cryptography\Helper::randomize($plain);
echo "> ciphered key is : '{$key}'" . PHP_EOL;
$c = new \Cryptography\SubstitutionCipher\Simple($plain, $key);
echo "> Simple object is : " . PHP_EOL;
echo var_export($c, 1) . PHP_EOL;
$crypted = $c->crypt($str);
echo "> crypted string is : " . $crypted . PHP_EOL;
$decrypted = $c->decrypt($crypted);
echo "> decrypted string is : " . $decrypted . PHP_EOL;
echo "> substitution table is:" . PHP_EOL . $c->substitutionTableToString() . PHP_EOL;
?>
            </pre>

            <p>Same example keeping spaces:</p>

            <pre>
 /**
  * Prepare the string to crypt/decrypt: this will return the string according to keys case
  *
  * @param $str
  * @return array|string
  */
 protected function _prepare($str)
 {
     return Helper::homogenizeString($str, $this->substitution_table->getPlaintextKey());
 }
Esempio n. 4
0
 /**
  * Debugging the substitution table
  *
  * @return string
  */
 public function substitutionTableToString()
 {
     $ciphers = $this->substitution_table->getSubstitutions();
     return Helper::tableToString($ciphers, array(), array(), __CLASS__ . ' Encryption Table');
 }
 /**
  * Debugging the substitutions table
  *
  * @return string
  */
 public function substitutionTableToString()
 {
     return Helper::tableToString($this->substitutions, str_split($this->plaintext_key), array(), get_class($this) . ' :: Substitution Table');
 }
 public function crypt($str)
 {
     $crypted = implode(' ', $this->substitution->crypt($str, true));
     return Helper::stripSpaces($crypted, ' ');
 }
 /**
  * Debugging the substitution table
  *
  * @return string
  */
 public function substitutionTableToString()
 {
     $ciphers = $this->substitution_table->getSubstitutions();
     $ciphers = $ciphers[0];
     foreach ($ciphers as $i => $list) {
         $ciphers[$i] = implode('-', $list);
     }
     return Helper::tableToString($ciphers, $this->substitution_table->getPlaintextKey(), array(), __CLASS__ . ' Encryption Table');
 }
 /**
  * Debugging
  *
  * @return string
  */
 public function substitutionTableToString()
 {
     return Helper::tableToString($this->getSubstitutionTable(), array(), array(), '"Tabula Recta" Table');
 }
 /**
  * Prepare the string
  *
  * @param $str
  * @return array|string
  */
 protected function _prepare($str)
 {
     return Helper::homogenizeString($str, $this->character_flag);
 }
 public function setUserKey($str)
 {
     $this->user_key = Helper::stripSpaces($str);
     return $this;
 }
 public function prepareString($str)
 {
     switch ($this->allowed_characters) {
         case Cryptography::ALPHABET_UPPER:
             $str = strtoupper($str);
             break;
         case Cryptography::ALPHABET_LOWER:
             $str = strtolower($str);
             break;
     }
     $str = Helper::sanitizeString($str, $this->allowed_characters_regex);
     return $str;
 }
Esempio n. 12
0
 /**
  * Reset the substitution table to its original form
  *
  * @return $this
  */
 protected function _reset()
 {
     parent::_reset();
     $this->substitution_table->setSubstitutions(array(str_split(Helper::rotate($this->substitution_table->getPlaintextKey(), $this->rotation_value - 1))));
     return $this;
 }
 /**
  * Debugging the substitution table
  *
  * @return string
  */
 public function substitutionTableToString()
 {
     $this->_reset();
     $ptk = $this->substitution_table->getPlaintextKey();
     $r = array();
     for ($i = 0; $i < floor(strlen($ptk) / $this->frequency); $i++) {
         if ($i > 0) {
             $this->substitution_table->rotate();
         }
         $ciphers = $this->substitution_table->getSubstitutions();
         $r[] = str_split($ciphers[0]);
     }
     return Helper::tableToString($r, str_split($ptk), array(), __CLASS__ . ' Encryption Table');
 }