5 * Copyright (c) 2006 - 2014 PHPExcel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * @package PHPExcel_Reader_Excel5
23 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version ##VERSION##, ##DATE##
29 * PHPExcel_Reader_Excel5_RC4
32 * @package PHPExcel_Reader_Excel5
33 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35 class PHPExcel_Reader_Excel5_RC4
43 * RC4 stream decryption/encryption constrcutor
45 * @param string $key Encryption key/passphrase
47 public function __construct($key)
51 for ($this->i
= 0; $this->i
< 256; $this->i++
) {
52 $this->s
[$this->i
] = $this->i
;
56 for ($this->i
= 0; $this->i
< 256; $this->i++
) {
57 $this->j
= ($this->j +
$this->s
[$this->i
] +
ord($key[$this->i %
$len])) %
256;
58 $t = $this->s
[$this->i
];
59 $this->s
[$this->i
] = $this->s
[$this->j
];
60 $this->s
[$this->j
] = $t;
62 $this->i
= $this->j
= 0;
66 * Symmetric decryption/encryption function
68 * @param string $data Data to encrypt/decrypt
72 public function RC4($data)
75 for ($c = 0; $c < $len; $c++
) {
76 $this->i
= ($this->i +
1) %
256;
77 $this->j
= ($this->j +
$this->s
[$this->i
]) %
256;
78 $t = $this->s
[$this->i
];
79 $this->s
[$this->i
] = $this->s
[$this->j
];
80 $this->s
[$this->j
] = $t;
82 $t = ($this->s
[$this->i
] +
$this->s
[$this->j
]) %
256;
84 $data[$c] = chr(ord($data[$c]) ^
$this->s
[$t]);