PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Reader / Xls / RC4.php

RC4.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Reader/Xls/RC4.php

60 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Reader\Xls;
4
5 class RC4
6 {
7 /** @var int[] */
8 protected array $s = []; // Context
9
10 protected int $i = 0;
11
12 protected int $j = 0;
13
14 /**
15 * RC4 stream decryption/encryption constructor.
16 *
17 * @param string $key Encryption key/passphrase
18 */
19 public function __construct(string $key)
20 {
21 $len = strlen($key);
22
23 for ($this->i = 0; $this->i < 256; ++$this->i) {
24 $this->s[$this->i] = $this->i;
25 }
26
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;
33 }
34 $this->i = $this->j = 0;
35 }
36
37 /**
38 * Symmetric decryption/encryption function.
39 *
40 * @param string $data Data to encrypt/decrypt
41 */
42 public function RC4(string $data): string
43 {
44 $len = strlen($data);
45 for ($c = 0; $c < $len; ++$c) {
46 $this->i = ($this->i + 1) % 256;
47 $this->j = ($this->j + $this->s[$this->i]) % 256;
48 $t = $this->s[$this->i];
49 $this->s[$this->i] = $this->s[$this->j];
50 $this->s[$this->j] = $t;
51
52 $t = ($this->s[$this->i] + $this->s[$this->j]) % 256;
53
54 $data[$c] = chr(ord($data[$c]) ^ $this->s[$t]);
55 }
56
57 return $data;
58 }
59 }
60