Updated gui for user facility settings (#1327)
[openemr.git] / vendor / phpoffice / phpexcel / Classes / PHPExcel / Reader / Excel5 / RC4.php
blob199ee1921cdc5944779ef26ebfee52c18fecafcd
1 <?php
2 /**
3 * PHPExcel
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
21 * @category PHPExcel
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##
28 /**
29 * PHPExcel_Reader_Excel5_RC4
31 * @category PHPExcel
32 * @package PHPExcel_Reader_Excel5
33 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35 class PHPExcel_Reader_Excel5_RC4
37 // Context
38 var $s = array();
39 var $i = 0;
40 var $j = 0;
42 /**
43 * RC4 stream decryption/encryption constrcutor
45 * @param string $key Encryption key/passphrase
47 public function __construct($key)
49 $len = strlen($key);
51 for ($this->i = 0; $this->i < 256; $this->i++) {
52 $this->s[$this->i] = $this->i;
55 $this->j = 0;
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;
65 /**
66 * Symmetric decryption/encryption function
68 * @param string $data Data to encrypt/decrypt
70 * @return string
72 public function RC4($data)
74 $len = strlen($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]);
86 return $data;