[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/Cipher/BlockMode/ -> ofb64.php (source)

   1  <?php
   2  /**
   3   * The Horde_Cipher_BlockMode_ofb64:: This class implements the
   4   * Horde_Cipher_BlockMode using a 64 bit output feedback.
   5   *
   6   * This can used to encrypt any length string and the encrypted version
   7   * will be the same length.
   8   *
   9   * $Horde: framework/Cipher/Cipher/BlockMode/ofb64.php,v 1.7.12.5 2006/01/01 21:28:11 jan Exp $
  10   *
  11   * Copyright 2002-2006 Mike Cochrane <mike@graftonhall.co.nz>
  12   *
  13   * See the enclosed file COPYING for license information (LGPL). If you
  14   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  15   *
  16   * @author  Mike Cochrane <mike@graftonhall.co.nz>
  17   * @since   Horde 2.2
  18   * @package Horde_Cipher
  19   */
  20  class Horde_Cipher_BlockMode_ofb64 extends Horde_Cipher_BlockMode {
  21  
  22      /**
  23       * Encrypt a string.
  24       *
  25       * @param Horde_Cipher $cipher  Cipher algorithm to use for
  26       *                              encryption.
  27       * @param string $plaintext     The data to encrypt.
  28       *
  29       * @return  The encrypted data.
  30       */
  31      function encrypt(&$cipher, $plaintext)
  32      {
  33          $encrypted = '';
  34  
  35          $n = 0;
  36          $jMax = strlen($plaintext);
  37          for ($j = 0; $j < $jMax; $j++) {
  38              if ($n == 0) {
  39                  $this->_iv = $cipher->encryptBlock($this->_iv);
  40              }
  41  
  42              $c = $plaintext[$j] ^ $this->_iv[$n];
  43              $encrypted .= $c;
  44  
  45              $n = (++$n) & 0x07;
  46          }
  47  
  48          return $encrypted;
  49      }
  50  
  51      /**
  52       * Decrypt a string.
  53       *
  54       * @param Horde_Cipher $cipher  Cipher algorithm to use for
  55       *                              decryption.
  56       * @param string $ciphertext    The data to decrypt.
  57       *
  58       * @return  The decrypted data.
  59       */
  60      function decrypt(&$cipher, $ciphertext)
  61      {
  62          $decrypted = '';
  63  
  64          $n = 0;
  65          $jMax = strlen($ciphertext);
  66          for ($j = 0; $j < $jMax; $j++) {
  67              if ($n == 0) {
  68                  $this->_iv = $cipher->encryptBlock($this->_iv);
  69              }
  70  
  71              $c = $ciphertext[$j] ^ $this->_iv[$n];
  72              $decrypted .= $c;
  73  
  74              $n = (++$n) & 0x07;
  75          }
  76  
  77          return $decrypted;
  78      }
  79  
  80  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7