updated a couple packages (#1567)
[openemr.git] / vendor / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Reader / Xls / RC4.php
blob691aca7c39855325d6f9295379742f1309b2d5a3
1 <?php
3 namespace PhpOffice\PhpSpreadsheet\Reader\Xls;
5 class RC4
7 // Context
8 protected $s = [];
10 protected $i = 0;
12 protected $j = 0;
14 /**
15 * RC4 stream decryption/encryption constrcutor.
17 * @param string $key Encryption key/passphrase
19 public function __construct($key)
21 $len = strlen($key);
23 for ($this->i = 0; $this->i < 256; ++$this->i) {
24 $this->s[$this->i] = $this->i;
27 $this->j = 0;
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;
37 /**
38 * Symmetric decryption/encryption function.
40 * @param string $data Data to encrypt/decrypt
42 * @return string
44 public function RC4($data)
46 $len = strlen($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]);
59 return $data;