[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * PHPExcel_Reader_Excel5_RC4 5 * 6 * Copyright (c) 2006 - 2015 PHPExcel 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 * 22 * @category PHPExcel 23 * @package PHPExcel_Reader_Excel5 24 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) 25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL 26 * @version ##VERSION##, ##DATE## 27 */ 28 class PHPExcel_Reader_Excel5_RC4 29 { 30 // Context 31 protected $s = array(); 32 protected $i = 0; 33 protected $j = 0; 34 35 /** 36 * RC4 stream decryption/encryption constrcutor 37 * 38 * @param string $key Encryption key/passphrase 39 */ 40 public function __construct($key) 41 { 42 $len = strlen($key); 43 44 for ($this->i = 0; $this->i < 256; $this->i++) { 45 $this->s[$this->i] = $this->i; 46 } 47 48 $this->j = 0; 49 for ($this->i = 0; $this->i < 256; $this->i++) { 50 $this->j = ($this->j + $this->s[$this->i] + ord($key[$this->i % $len])) % 256; 51 $t = $this->s[$this->i]; 52 $this->s[$this->i] = $this->s[$this->j]; 53 $this->s[$this->j] = $t; 54 } 55 $this->i = $this->j = 0; 56 } 57 58 /** 59 * Symmetric decryption/encryption function 60 * 61 * @param string $data Data to encrypt/decrypt 62 * 63 * @return string 64 */ 65 public function RC4($data) 66 { 67 $len = strlen($data); 68 for ($c = 0; $c < $len; $c++) { 69 $this->i = ($this->i + 1) % 256; 70 $this->j = ($this->j + $this->s[$this->i]) % 256; 71 $t = $this->s[$this->i]; 72 $this->s[$this->i] = $this->s[$this->j]; 73 $this->s[$this->j] = $t; 74 75 $t = ($this->s[$this->i] + $this->s[$this->j]) % 256; 76 77 $data[$c] = chr(ord($data[$c]) ^ $this->s[$t]); 78 } 79 return $data; 80 } 81 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |