/usr/share/php/Crypt/Blowfish/ECB.php is in php-crypt-blowfish 1.1.0~RC2-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | <?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* PHP implementation of the Blowfish algorithm in ECB mode
*
* PHP versions 4 and 5
*
* @category Encryption
* @package Crypt_Blowfish
* @author Matthew Fonda <mfonda@php.net>
* @author Philippe Jausions <jausions@php.net>
* @copyright 2005-2008 Matthew Fonda
* @license http://www.opensource.net/licenses/bsd-license.php New BSD
* @version CVS: $Id: ECB.php,v 1.7 2008/08/30 21:53:50 jausions Exp $
* @link http://pear.php.net/package/Crypt_Blowfish
* @since 1.1.0
*/
/**
* Required parent class
*/
require_once 'Crypt/Blowfish/PHP.php';
/**
* Example
* <code>
* $bf =& Crypt_Blowfish::factory('ecb');
* if (PEAR::isError($bf)) {
* echo $bf->getMessage();
* exit;
* }
* $bf->setKey('My secret key');
* $encrypted = $bf->encrypt('this is some example plain text');
* $plaintext = $bf->decrypt($encrypted);
* echo "plain text: $plaintext";
* </code>
*
* @category Encryption
* @package Crypt_Blowfish
* @author Matthew Fonda <mfonda@php.net>
* @author Philippe Jausions <jausions@php.net>
* @copyright 2005-2008 Matthew Fonda
* @license http://www.opensource.net/licenses/bsd-license.php New BSD
* @link http://pear.php.net/package/Crypt_Blowfish
* @version 1.1.0RC2
* @since 1.1.0
*/
class Crypt_Blowfish_ECB extends Crypt_Blowfish_PHP
{
/**
* Crypt_Blowfish Constructor
* Initializes the Crypt_Blowfish object, and sets
* the secret key
*
* @param string $key
* @param string $iv initialization vector
* @access public
*/
function Crypt_Blowfish_ECB($key = null, $iv = null)
{
$this->__construct($key, $iv);
}
/**
* Class constructor
*
* @param string $key
* @param string $iv initialization vector
* @access public
*/
function __construct($key = null, $iv = null)
{
$this->_iv_required = false;
parent::__construct($key, $iv);
}
/**
* Encrypts a string
*
* Value is padded with NUL characters prior to encryption. You may
* need to trim or cast the type when you decrypt.
*
* @param string $plainText string of characters/bytes to encrypt
* @return string|PEAR_Error Returns cipher text on success, PEAR_Error on failure
* @access public
*/
function encrypt($plainText)
{
if (!is_string($plainText)) {
return PEAR::raiseError('Input must be a string', 0);
} elseif (empty($this->_P)) {
return PEAR::raiseError('The key is not initialized.', 8);
}
$cipherText = '';
$len = strlen($plainText);
$plainText .= str_repeat(chr(0), (8 - ($len % 8)) % 8);
for ($i = 0; $i < $len; $i += 8) {
list(, $Xl, $Xr) = unpack('N2', substr($plainText, $i, 8));
$this->_encipher($Xl, $Xr);
$cipherText .= pack('N2', $Xl, $Xr);
}
return $cipherText;
}
/**
* Decrypts an encrypted string
*
* The value was padded with NUL characters when encrypted. You may
* need to trim the result or cast its type.
*
* @param string $cipherText
* @return string|PEAR_Error Returns plain text on success, PEAR_Error on failure
* @access public
*/
function decrypt($cipherText)
{
if (!is_string($cipherText)) {
return PEAR::raiseError('Cipher text must be a string', 1);
}
if (empty($this->_P)) {
return PEAR::raiseError('The key is not initialized.', 8);
}
$plainText = '';
$len = strlen($cipherText);
$cipherText .= str_repeat(chr(0), (8 - ($len % 8)) % 8);
for ($i = 0; $i < $len; $i += 8) {
list(, $Xl, $Xr) = unpack('N2', substr($cipherText, $i, 8));
$this->_decipher($Xl, $Xr);
$plainText .= pack('N2', $Xl, $Xr);
}
return $plainText;
}
}
?>
|