2013-10-29 11:25:36 +00:00
|
|
|
<?php
|
2015-05-18 15:39:04 +00:00
|
|
|
|
2013-10-29 11:25:36 +00:00
|
|
|
/**
|
2015-05-18 15:39:04 +00:00
|
|
|
* PHPExcel_Reader_Excel5_RC4
|
2013-10-29 11:25:36 +00:00
|
|
|
*
|
2015-05-02 22:50:37 +00:00
|
|
|
* Copyright (c) 2006 - 2015 PHPExcel
|
2013-10-29 11:25:36 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* @category PHPExcel
|
|
|
|
* @package PHPExcel_Reader_Excel5
|
2015-05-02 22:50:37 +00:00
|
|
|
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
2015-05-12 09:22:06 +00:00
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
2013-10-29 11:25:36 +00:00
|
|
|
* @version ##VERSION##, ##DATE##
|
|
|
|
*/
|
|
|
|
class PHPExcel_Reader_Excel5_RC4
|
|
|
|
{
|
2015-05-12 09:22:06 +00:00
|
|
|
// Context
|
2015-05-17 18:00:00 +00:00
|
|
|
protected $s = array();
|
|
|
|
protected $i = 0;
|
|
|
|
protected $j = 0;
|
2013-10-29 11:25:36 +00:00
|
|
|
|
2015-05-12 09:22:06 +00:00
|
|
|
/**
|
|
|
|
* RC4 stream decryption/encryption constrcutor
|
2015-05-17 10:11:56 +00:00
|
|
|
*
|
2015-05-12 09:22:06 +00:00
|
|
|
* @param string $key Encryption key/passphrase
|
|
|
|
*/
|
|
|
|
public function __construct($key)
|
|
|
|
{
|
|
|
|
$len = strlen($key);
|
2013-10-29 11:25:36 +00:00
|
|
|
|
2015-05-12 09:22:06 +00:00
|
|
|
for ($this->i = 0; $this->i < 256; $this->i++) {
|
|
|
|
$this->s[$this->i] = $this->i;
|
|
|
|
}
|
2013-10-29 11:25:36 +00:00
|
|
|
|
2015-05-12 09:22:06 +00:00
|
|
|
$this->j = 0;
|
|
|
|
for ($this->i = 0; $this->i < 256; $this->i++) {
|
|
|
|
$this->j = ($this->j + $this->s[$this->i] + ord($key[$this->i % $len])) % 256;
|
|
|
|
$t = $this->s[$this->i];
|
|
|
|
$this->s[$this->i] = $this->s[$this->j];
|
|
|
|
$this->s[$this->j] = $t;
|
|
|
|
}
|
|
|
|
$this->i = $this->j = 0;
|
|
|
|
}
|
2013-10-29 11:25:36 +00:00
|
|
|
|
2015-05-12 09:22:06 +00:00
|
|
|
/**
|
|
|
|
* Symmetric decryption/encryption function
|
2015-05-17 10:11:56 +00:00
|
|
|
*
|
2015-05-12 09:22:06 +00:00
|
|
|
* @param string $data Data to encrypt/decrypt
|
2015-05-17 10:11:56 +00:00
|
|
|
*
|
2015-05-12 09:22:06 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function RC4($data)
|
|
|
|
{
|
|
|
|
$len = strlen($data);
|
|
|
|
for ($c = 0; $c < $len; $c++) {
|
|
|
|
$this->i = ($this->i + 1) % 256;
|
|
|
|
$this->j = ($this->j + $this->s[$this->i]) % 256;
|
|
|
|
$t = $this->s[$this->i];
|
|
|
|
$this->s[$this->i] = $this->s[$this->j];
|
|
|
|
$this->s[$this->j] = $t;
|
2013-10-29 11:25:36 +00:00
|
|
|
|
2015-05-12 09:22:06 +00:00
|
|
|
$t = ($this->s[$this->i] + $this->s[$this->j]) % 256;
|
2013-10-29 11:25:36 +00:00
|
|
|
|
2015-05-12 09:22:06 +00:00
|
|
|
$data[$c] = chr(ord($data[$c]) ^ $this->s[$t]);
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
2013-10-29 11:25:36 +00:00
|
|
|
}
|