1<?php
2/**
3 * Copyright 2005-2008 Matthew Fonda <mfonda@php.net>
4 * Copyright 2008 Philippe Jausions <jausions@php.net>
5 * Copyright 2012-2017 Horde LLC (http://www.horde.org/)
6 *
7 * See the enclosed file COPYING for license information (LGPL). If you
8 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
9 *
10 * @author   Matthew Fonda <mfonda@php.net>
11 * @author   Philippe Jausions <jausions@php.net>
12 * @author   Michael Slusarz <slusarz@horde.org>
13 * @category Horde
14 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
15 * @package  Crypt_Blowfish
16 */
17
18/**
19 * PHP implementation of the Blowfish algorithm in ECB mode.
20 *
21 * @author    Matthew Fonda <mfonda@php.net>
22 * @author    Philippe Jausions <jausions@php.net>
23 * @author    Michael Slusarz <slusarz@horde.org>
24 * @category  Horde
25 * @copyright 2005-2008 Matthew Fonda
26 * @copyright 2008 Philippe Jausions
27 * @copyright 2012-2017 Horde LLC
28 * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
29 * @package   Crypt_Blowfish
30 */
31class Horde_Crypt_Blowfish_Php_Ecb extends Horde_Crypt_Blowfish_Php_Base
32{
33    /**
34     */
35    public function encrypt($text, $iv)
36    {
37        $cipherText = '';
38        $len = strlen($text);
39
40        for ($i = 0; $i < $len; $i += 8) {
41            list(, $Xl, $Xr) = unpack('N2', substr($text, $i, 8));
42            $this->_encipher($Xl, $Xr);
43            $cipherText .= pack('N2', $Xl, $Xr);
44        }
45
46        return $cipherText;
47    }
48
49    /**
50     */
51    public function decrypt($text, $iv)
52    {
53        $plainText = '';
54        $len = strlen($text);
55
56        for ($i = 0; $i < $len; $i += 8) {
57            list(, $Xl, $Xr) = unpack('N2', substr($text, $i, 8));
58            $this->_decipher($Xl, $Xr);
59            $plainText .= pack('N2', $Xl, $Xr);
60        }
61
62        return $plainText;
63    }
64
65}
66