3 namespace PhpOffice\PhpSpreadsheet\Reader\Xls
;
15 * RC4 stream decryption/encryption constrcutor.
17 * @param string $key Encryption key/passphrase
19 public function __construct($key)
23 for ($this->i
= 0; $this->i
< 256; ++
$this->i
) {
24 $this->s
[$this->i
] = $this->i
;
28 for ($this->i
= 0; $this->i
< 256; ++
$this->i
) {
29 $this->j
= ($this->j +
$this->s
[$this->i
] +
ord($key[$this->i %
$len])) %
256;
30 $t = $this->s
[$this->i
];
31 $this->s
[$this->i
] = $this->s
[$this->j
];
32 $this->s
[$this->j
] = $t;
34 $this->i
= $this->j
= 0;
38 * Symmetric decryption/encryption function.
40 * @param string $data Data to encrypt/decrypt
44 public function RC4($data)
47 for ($c = 0; $c < $len; ++
$c) {
48 $this->i
= ($this->i +
1) %
256;
49 $this->j
= ($this->j +
$this->s
[$this->i
]) %
256;
50 $t = $this->s
[$this->i
];
51 $this->s
[$this->i
] = $this->s
[$this->j
];
52 $this->s
[$this->j
] = $t;
54 $t = ($this->s
[$this->i
] +
$this->s
[$this->j
]) %
256;
56 $data[$c] = chr(ord($data[$c]) ^
$this->s
[$t]);