PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.18
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.18
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / vendor_prefixed / chillerlan / php-qrcode / src / Common / GF256.php

GF256.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.18, at vendor_prefixed/chillerlan/php-qrcode/src/Common/GF256.php

361 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class GF256
5 *
6 * @created 16.01.2021
7 * @author ZXing Authors
8 * @author Smiley <smiley@chillerlan.net>
9 * @copyright 2021 Smiley
10 * @license Apache-2.0
11 */
12 namespace WCPOS\Vendor\chillerlan\QRCode\Common;
13
14 use WCPOS\Vendor\chillerlan\QRCode\QRCodeException;
15 use function array_fill;
16 /**
17 * This class contains utility methods for performing mathematical operations over
18 * the Galois Fields. Operations use a given primitive polynomial in calculations.
19 *
20 * Throughout this package, elements of the GF are represented as an int
21 * for convenience and speed (but at the cost of memory).
22 *
23 *
24 * @author Sean Owen
25 * @author David Olivier
26 */
27 final class GF256
28 {
29 /**
30 * irreducible polynomial whose coefficients are represented by the bits of an int,
31 * where the least-significant bit represents the constant coefficient
32 */
33 # private int $primitive = 0x011D;
34 private const logTable = [
35 0,
36 // the first value is never returned, index starts at 1
37 0,
38 1,
39 25,
40 2,
41 50,
42 26,
43 198,
44 3,
45 223,
46 51,
47 238,
48 27,
49 104,
50 199,
51 75,
52 4,
53 100,
54 224,
55 14,
56 52,
57 141,
58 239,
59 129,
60 28,
61 193,
62 105,
63 248,
64 200,
65 8,
66 76,
67 113,
68 5,
69 138,
70 101,
71 47,
72 225,
73 36,
74 15,
75 33,
76 53,
77 147,
78 142,
79 218,
80 240,
81 18,
82 130,
83 69,
84 29,
85 181,
86 194,
87 125,
88 106,
89 39,
90 249,
91 185,
92 201,
93 154,
94 9,
95 120,
96 77,
97 228,
98 114,
99 166,
100 6,
101 191,
102 139,
103 98,
104 102,
105 221,
106 48,
107 253,
108 226,
109 152,
110 37,
111 179,
112 16,
113 145,
114 34,
115 136,
116 54,
117 208,
118 148,
119 206,
120 143,
121 150,
122 219,
123 189,
124 241,
125 210,
126 19,
127 92,
128 131,
129 56,
130 70,
131 64,
132 30,
133 66,
134 182,
135 163,
136 195,
137 72,
138 126,
139 110,
140 107,
141 58,
142 40,
143 84,
144 250,
145 133,
146 186,
147 61,
148 202,
149 94,
150 155,
151 159,
152 10,
153 21,
154 121,
155 43,
156 78,
157 212,
158 229,
159 172,
160 115,
161 243,
162 167,
163 87,
164 7,
165 112,
166 192,
167 247,
168 140,
169 128,
170 99,
171 13,
172 103,
173 74,
174 222,
175 237,
176 49,
177 197,
178 254,
179 24,
180 227,
181 165,
182 153,
183 119,
184 38,
185 184,
186 180,
187 124,
188 17,
189 68,
190 146,
191 217,
192 35,
193 32,
194 137,
195 46,
196 55,
197 63,
198 209,
199 91,
200 149,
201 188,
202 207,
203 205,
204 144,
205 135,
206 151,
207 178,
208 220,
209 252,
210 190,
211 97,
212 242,
213 86,
214 211,
215 171,
216 20,
217 42,
218 93,
219 158,
220 132,
221 60,
222 57,
223 83,
224 71,
225 109,
226 65,
227 162,
228 31,
229 45,
230 67,
231 216,
232 183,
233 123,
234 164,
235 118,
236 196,
237 23,
238 73,
239 236,
240 127,
241 12,
242 111,
243 246,
244 108,
245 161,
246 59,
247 82,
248 41,
249 157,
250 85,
251 170,
252 251,
253 96,
254 134,
255 177,
256 187,
257 204,
258 62,
259 90,
260 203,
261 89,
262 95,
263 176,
264 156,
265 169,
266 160,
267 81,
268 11,
269 245,
270 22,
271 235,
272 122,
273 117,
274 44,
275 215,
276 79,
277 174,
278 213,
279 233,
280 230,
281 231,
282 173,
283 232,
284 116,
285 214,
286 244,
287 234,
288 168,
289 80,
290 88,
291 175,
292 ];
293 private const expTable = [1, 2, 4, 8, 16, 32, 64, 128, 29, 58, 116, 232, 205, 135, 19, 38, 76, 152, 45, 90, 180, 117, 234, 201, 143, 3, 6, 12, 24, 48, 96, 192, 157, 39, 78, 156, 37, 74, 148, 53, 106, 212, 181, 119, 238, 193, 159, 35, 70, 140, 5, 10, 20, 40, 80, 160, 93, 186, 105, 210, 185, 111, 222, 161, 95, 190, 97, 194, 153, 47, 94, 188, 101, 202, 137, 15, 30, 60, 120, 240, 253, 231, 211, 187, 107, 214, 177, 127, 254, 225, 223, 163, 91, 182, 113, 226, 217, 175, 67, 134, 17, 34, 68, 136, 13, 26, 52, 104, 208, 189, 103, 206, 129, 31, 62, 124, 248, 237, 199, 147, 59, 118, 236, 197, 151, 51, 102, 204, 133, 23, 46, 92, 184, 109, 218, 169, 79, 158, 33, 66, 132, 21, 42, 84, 168, 77, 154, 41, 82, 164, 85, 170, 73, 146, 57, 114, 228, 213, 183, 115, 230, 209, 191, 99, 198, 145, 63, 126, 252, 229, 215, 179, 123, 246, 241, 255, 227, 219, 171, 75, 150, 49, 98, 196, 149, 55, 110, 220, 165, 87, 174, 65, 130, 25, 50, 100, 200, 141, 7, 14, 28, 56, 112, 224, 221, 167, 83, 166, 81, 162, 89, 178, 121, 242, 249, 239, 195, 155, 43, 86, 172, 69, 138, 9, 18, 36, 72, 144, 61, 122, 244, 245, 247, 243, 251, 235, 203, 139, 11, 22, 44, 88, 176, 125, 250, 233, 207, 131, 27, 54, 108, 216, 173, 71, 142, 1];
294 /**
295 * Implements both addition and subtraction -- they are the same in GF(size).
296 *
297 * @return int sum/difference of a and b
298 */
299 public static function addOrSubtract(int $a, int $b) : int
300 {
301 return $a ^ $b;
302 }
303 /**
304 * @return GenericGFPoly the monomial representing coefficient * x^degree
305 * @throws \chillerlan\QRCode\QRCodeException
306 */
307 public static function buildMonomial(int $degree, int $coefficient) : GenericGFPoly
308 {
309 if ($degree < 0) {
310 throw new QRCodeException('degree < 0');
311 }
312 $coefficients = array_fill(0, $degree + 1, 0);
313 $coefficients[0] = $coefficient;
314 return new GenericGFPoly($coefficients);
315 }
316 /**
317 * @return int 2 to the power of $a in GF(size)
318 */
319 public static function exp(int $a) : int
320 {
321 if ($a < 0) {
322 $a += 255;
323 } elseif ($a >= 256) {
324 $a -= 255;
325 }
326 return self::expTable[$a];
327 }
328 /**
329 * @return int base 2 log of $a in GF(size)
330 * @throws \chillerlan\QRCode\QRCodeException
331 */
332 public static function log(int $a) : int
333 {
334 if ($a < 1) {
335 throw new QRCodeException('$a < 1');
336 }
337 return self::logTable[$a];
338 }
339 /**
340 * @return int multiplicative inverse of a
341 * @throws \chillerlan\QRCode\QRCodeException
342 */
343 public static function inverse(int $a) : int
344 {
345 if ($a === 0) {
346 throw new QRCodeException('$a === 0');
347 }
348 return self::expTable[256 - self::logTable[$a] - 1];
349 }
350 /**
351 * @return int product of a and b in GF(size)
352 */
353 public static function multiply(int $a, int $b) : int
354 {
355 if ($a === 0 || $b === 0) {
356 return 0;
357 }
358 return self::expTable[(self::logTable[$a] + self::logTable[$b]) % 255];
359 }
360 }
361