@@ 45-66 (lines=22) @@ | ||
42 | * |
|
43 | * @return array |
|
44 | */ |
|
45 | public function generateTable(int $polynomial): array |
|
46 | { |
|
47 | $tableSize = 256; |
|
48 | ||
49 | $table = []; |
|
50 | ||
51 | for ($iterator = 0; $iterator < $tableSize; ++$iterator) { |
|
52 | $temp = 0; |
|
53 | $a = ($iterator << 8); |
|
54 | for ($j = 0; $j < 8; ++$j) { |
|
55 | if ((($temp ^ $a) & 0x8000) !== 0) { |
|
56 | $temp = (($temp << 1) ^ $polynomial); |
|
57 | } else { |
|
58 | $temp <<= 1; |
|
59 | } |
|
60 | $a <<= 1; |
|
61 | } |
|
62 | $table[$iterator] = $temp & 0xffff; |
|
63 | } |
|
64 | ||
65 | return $table; |
|
66 | } |
|
67 | } |
|
68 |
@@ 45-66 (lines=22) @@ | ||
42 | * |
|
43 | * @return array |
|
44 | */ |
|
45 | public function generateTable(int $polynomial): array |
|
46 | { |
|
47 | $tableSize = 256; |
|
48 | ||
49 | $table = []; |
|
50 | ||
51 | for ($iterator = 0; $iterator < $tableSize; ++$iterator) { |
|
52 | $temp = 0; |
|
53 | $a = $iterator; |
|
54 | for ($j = 0; $j < 8; ++$j) { |
|
55 | if ((($temp ^ $a) & 0x80) !== 0) { |
|
56 | $temp = (($temp << 1) ^ $polynomial); |
|
57 | } else { |
|
58 | $temp <<= 1; |
|
59 | } |
|
60 | $a <<= 1; |
|
61 | } |
|
62 | $table[$iterator] = $temp & 0xff; |
|
63 | } |
|
64 | ||
65 | return $table; |
|
66 | } |
|
67 | } |
|
68 |