3
* The Horde_Cipher_BlockMode_ecb:: This class implements the
4
* Horde_Cipher_BlockMode using the Electronic Code Book method of
5
* encrypting blocks of data.
7
* $Horde: framework/Cipher/Cipher/BlockMode/ecb.php,v 1.7.12.1 2005/01/03 12:18:56 jan Exp $
9
* Copyright 2002-2005 Mike Cochrane <mike@graftonhall.co.nz>
11
* See the enclosed file COPYING for license information (LGPL). If you
12
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
14
* @author Mike Cochrane <mike@graftonhall.co.nz>
15
* @version $Revision: 1.7.12.1 $
17
* @package Horde_Cipher
19
class Horde_Cipher_BlockMode_ecb extends Horde_Cipher_BlockMode {
21
function encrypt(&$cipher, $plaintext)
24
$blocksize = $cipher->getBlockSize();
26
$jMax = strlen($plaintext);
27
for ($j = 0; $j < $jMax; $j += $blocksize) {
28
$plain = substr($plaintext, $j, $blocksize);
30
if (strlen($plain) < $blocksize) {
31
// pad the block with \0's if it's not long enough
32
$plain = str_pad($plain, 8, "\0");
35
$encrypted .= $cipher->encryptBlock($plain);
41
function decrypt(&$cipher, $ciphertext)
44
$blocksize = $cipher->getBlockSize();
46
$jMax = strlen($ciphertext);
47
for ($j = 0; $j < $jMax; $j += $blocksize) {
48
$plain = substr($ciphertext, $j, $blocksize);
49
$decrypted .= $cipher->decryptBlock($plain);
52
// remove trailing \0's used to pad the last block
53
while (substr($decrypted, -1, 1) == "\0") {
54
$decrypted = substr($decrypted, 0, -1);