pixel-react 1.15.17 → 1.15.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/lib/_virtual/index10.js +2 -2
  2. package/lib/_virtual/index11.js +2 -2
  3. package/lib/_virtual/index9.js +2 -2
  4. package/lib/index.cjs +5568 -20
  5. package/lib/index.cjs.map +1 -1
  6. package/lib/index.d.ts +1 -1
  7. package/lib/node_modules/js-beautify/js/src/css/beautifier.js +1 -1
  8. package/lib/node_modules/js-beautify/js/src/css/index.js +1 -1
  9. package/lib/node_modules/js-beautify/js/src/css/options.js +1 -1
  10. package/lib/node_modules/js-beautify/js/src/html/index.js +1 -1
  11. package/lib/node_modules/js-beautify/js/src/html/options.js +1 -1
  12. package/lib/node_modules/js-beautify/js/src/javascript/beautifier.js +1 -1
  13. package/lib/node_modules/js-beautify/js/src/javascript/index.js +1 -1
  14. package/lib/node_modules/jsencrypt/lib/JSEncrypt.js +246 -0
  15. package/lib/node_modules/jsencrypt/lib/JSEncrypt.js.map +1 -0
  16. package/lib/node_modules/jsencrypt/lib/JSEncryptRSAKey.js +325 -0
  17. package/lib/node_modules/jsencrypt/lib/JSEncryptRSAKey.js.map +1 -0
  18. package/lib/node_modules/jsencrypt/lib/index.js +6 -0
  19. package/lib/node_modules/jsencrypt/lib/index.js.map +1 -0
  20. package/lib/node_modules/jsencrypt/lib/lib/asn1js/asn1.js +570 -0
  21. package/lib/node_modules/jsencrypt/lib/lib/asn1js/asn1.js.map +1 -0
  22. package/lib/node_modules/jsencrypt/lib/lib/asn1js/base64.js +88 -0
  23. package/lib/node_modules/jsencrypt/lib/lib/asn1js/base64.js.map +1 -0
  24. package/lib/node_modules/jsencrypt/lib/lib/asn1js/hex.js +66 -0
  25. package/lib/node_modules/jsencrypt/lib/lib/asn1js/hex.js.map +1 -0
  26. package/lib/node_modules/jsencrypt/lib/lib/asn1js/int10.js +87 -0
  27. package/lib/node_modules/jsencrypt/lib/lib/asn1js/int10.js.map +1 -0
  28. package/lib/node_modules/jsencrypt/lib/lib/jsbn/base64.js +65 -0
  29. package/lib/node_modules/jsencrypt/lib/lib/jsbn/base64.js.map +1 -0
  30. package/lib/node_modules/jsencrypt/lib/lib/jsbn/jsbn.js +1700 -0
  31. package/lib/node_modules/jsencrypt/lib/lib/jsbn/jsbn.js.map +1 -0
  32. package/lib/node_modules/jsencrypt/lib/lib/jsbn/prng4.js +48 -0
  33. package/lib/node_modules/jsencrypt/lib/lib/jsbn/prng4.js.map +1 -0
  34. package/lib/node_modules/jsencrypt/lib/lib/jsbn/rng.js +77 -0
  35. package/lib/node_modules/jsencrypt/lib/lib/jsbn/rng.js.map +1 -0
  36. package/lib/node_modules/jsencrypt/lib/lib/jsbn/rsa.js +415 -0
  37. package/lib/node_modules/jsencrypt/lib/lib/jsbn/rsa.js.map +1 -0
  38. package/lib/node_modules/jsencrypt/lib/lib/jsbn/sha256.js +307 -0
  39. package/lib/node_modules/jsencrypt/lib/lib/jsbn/sha256.js.map +1 -0
  40. package/lib/node_modules/jsencrypt/lib/lib/jsbn/util.js +61 -0
  41. package/lib/node_modules/jsencrypt/lib/lib/jsbn/util.js.map +1 -0
  42. package/lib/node_modules/jsencrypt/lib/lib/jsrsasign/asn1-1.0.js +1559 -0
  43. package/lib/node_modules/jsencrypt/lib/lib/jsrsasign/asn1-1.0.js.map +1 -0
  44. package/lib/utils/getEncryptedData/getEncryptedData.d.ts +1 -1
  45. package/lib/utils/getEncryptedData/getEncryptedData.js +8 -17
  46. package/lib/utils/getEncryptedData/getEncryptedData.js.map +1 -1
  47. package/package.json +2 -1
@@ -0,0 +1,1700 @@
1
+ import { op_and, op_or, op_xor, op_andnot, lbit, cbit, int2char } from './util.js';
2
+
3
+ // Copyright (c) 2005 Tom Wu
4
+ // All Rights Reserved.
5
+ // See "LICENSE" for details.
6
+ // Basic JavaScript BN library - subset useful for RSA encryption.
7
+ // Bits per digit
8
+ var dbits;
9
+ // JavaScript engine analysis
10
+ var canary = 0xdeadbeefcafe;
11
+ var j_lm = (canary & 0xffffff) == 0xefcafe;
12
+ //#region
13
+ var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997];
14
+ var lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
15
+ //#endregion
16
+ // (public) Constructor
17
+ var BigInteger = /** @class */function () {
18
+ function BigInteger(a, b, c) {
19
+ if (a != null) {
20
+ if ("number" == typeof a) {
21
+ this.fromNumber(a, b, c);
22
+ } else if (b == null && "string" != typeof a) {
23
+ this.fromString(a, 256);
24
+ } else {
25
+ this.fromString(a, b);
26
+ }
27
+ }
28
+ }
29
+ //#region PUBLIC
30
+ // BigInteger.prototype.toString = bnToString;
31
+ // (public) return string representation in given radix
32
+ BigInteger.prototype.toString = function (b) {
33
+ if (this.s < 0) {
34
+ return "-" + this.negate().toString(b);
35
+ }
36
+ var k;
37
+ if (b == 16) {
38
+ k = 4;
39
+ } else if (b == 8) {
40
+ k = 3;
41
+ } else if (b == 2) {
42
+ k = 1;
43
+ } else if (b == 32) {
44
+ k = 5;
45
+ } else if (b == 4) {
46
+ k = 2;
47
+ } else {
48
+ return this.toRadix(b);
49
+ }
50
+ var km = (1 << k) - 1;
51
+ var d;
52
+ var m = false;
53
+ var r = "";
54
+ var i = this.t;
55
+ var p = this.DB - i * this.DB % k;
56
+ if (i-- > 0) {
57
+ if (p < this.DB && (d = this[i] >> p) > 0) {
58
+ m = true;
59
+ r = int2char(d);
60
+ }
61
+ while (i >= 0) {
62
+ if (p < k) {
63
+ d = (this[i] & (1 << p) - 1) << k - p;
64
+ d |= this[--i] >> (p += this.DB - k);
65
+ } else {
66
+ d = this[i] >> (p -= k) & km;
67
+ if (p <= 0) {
68
+ p += this.DB;
69
+ --i;
70
+ }
71
+ }
72
+ if (d > 0) {
73
+ m = true;
74
+ }
75
+ if (m) {
76
+ r += int2char(d);
77
+ }
78
+ }
79
+ }
80
+ return m ? r : "0";
81
+ };
82
+ // BigInteger.prototype.negate = bnNegate;
83
+ // (public) -this
84
+ BigInteger.prototype.negate = function () {
85
+ var r = nbi();
86
+ BigInteger.ZERO.subTo(this, r);
87
+ return r;
88
+ };
89
+ // BigInteger.prototype.abs = bnAbs;
90
+ // (public) |this|
91
+ BigInteger.prototype.abs = function () {
92
+ return this.s < 0 ? this.negate() : this;
93
+ };
94
+ // BigInteger.prototype.compareTo = bnCompareTo;
95
+ // (public) return + if this > a, - if this < a, 0 if equal
96
+ BigInteger.prototype.compareTo = function (a) {
97
+ var r = this.s - a.s;
98
+ if (r != 0) {
99
+ return r;
100
+ }
101
+ var i = this.t;
102
+ r = i - a.t;
103
+ if (r != 0) {
104
+ return this.s < 0 ? -r : r;
105
+ }
106
+ while (--i >= 0) {
107
+ if ((r = this[i] - a[i]) != 0) {
108
+ return r;
109
+ }
110
+ }
111
+ return 0;
112
+ };
113
+ // BigInteger.prototype.bitLength = bnBitLength;
114
+ // (public) return the number of bits in "this"
115
+ BigInteger.prototype.bitLength = function () {
116
+ if (this.t <= 0) {
117
+ return 0;
118
+ }
119
+ return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ this.s & this.DM);
120
+ };
121
+ // BigInteger.prototype.mod = bnMod;
122
+ // (public) this mod a
123
+ BigInteger.prototype.mod = function (a) {
124
+ var r = nbi();
125
+ this.abs().divRemTo(a, null, r);
126
+ if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
127
+ a.subTo(r, r);
128
+ }
129
+ return r;
130
+ };
131
+ // BigInteger.prototype.modPowInt = bnModPowInt;
132
+ // (public) this^e % m, 0 <= e < 2^32
133
+ BigInteger.prototype.modPowInt = function (e, m) {
134
+ var z;
135
+ if (e < 256 || m.isEven()) {
136
+ z = new Classic(m);
137
+ } else {
138
+ z = new Montgomery(m);
139
+ }
140
+ return this.exp(e, z);
141
+ };
142
+ // BigInteger.prototype.clone = bnClone;
143
+ // (public)
144
+ BigInteger.prototype.clone = function () {
145
+ var r = nbi();
146
+ this.copyTo(r);
147
+ return r;
148
+ };
149
+ // BigInteger.prototype.intValue = bnIntValue;
150
+ // (public) return value as integer
151
+ BigInteger.prototype.intValue = function () {
152
+ if (this.s < 0) {
153
+ if (this.t == 1) {
154
+ return this[0] - this.DV;
155
+ } else if (this.t == 0) {
156
+ return -1;
157
+ }
158
+ } else if (this.t == 1) {
159
+ return this[0];
160
+ } else if (this.t == 0) {
161
+ return 0;
162
+ }
163
+ // assumes 16 < DB < 32
164
+ return (this[1] & (1 << 32 - this.DB) - 1) << this.DB | this[0];
165
+ };
166
+ // BigInteger.prototype.byteValue = bnByteValue;
167
+ // (public) return value as byte
168
+ BigInteger.prototype.byteValue = function () {
169
+ return this.t == 0 ? this.s : this[0] << 24 >> 24;
170
+ };
171
+ // BigInteger.prototype.shortValue = bnShortValue;
172
+ // (public) return value as short (assumes DB>=16)
173
+ BigInteger.prototype.shortValue = function () {
174
+ return this.t == 0 ? this.s : this[0] << 16 >> 16;
175
+ };
176
+ // BigInteger.prototype.signum = bnSigNum;
177
+ // (public) 0 if this == 0, 1 if this > 0
178
+ BigInteger.prototype.signum = function () {
179
+ if (this.s < 0) {
180
+ return -1;
181
+ } else if (this.t <= 0 || this.t == 1 && this[0] <= 0) {
182
+ return 0;
183
+ } else {
184
+ return 1;
185
+ }
186
+ };
187
+ // BigInteger.prototype.toByteArray = bnToByteArray;
188
+ // (public) convert to bigendian byte array
189
+ BigInteger.prototype.toByteArray = function () {
190
+ var i = this.t;
191
+ var r = [];
192
+ r[0] = this.s;
193
+ var p = this.DB - i * this.DB % 8;
194
+ var d;
195
+ var k = 0;
196
+ if (i-- > 0) {
197
+ if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) {
198
+ r[k++] = d | this.s << this.DB - p;
199
+ }
200
+ while (i >= 0) {
201
+ if (p < 8) {
202
+ d = (this[i] & (1 << p) - 1) << 8 - p;
203
+ d |= this[--i] >> (p += this.DB - 8);
204
+ } else {
205
+ d = this[i] >> (p -= 8) & 0xff;
206
+ if (p <= 0) {
207
+ p += this.DB;
208
+ --i;
209
+ }
210
+ }
211
+ if ((d & 0x80) != 0) {
212
+ d |= -256;
213
+ }
214
+ if (k == 0 && (this.s & 0x80) != (d & 0x80)) {
215
+ ++k;
216
+ }
217
+ if (k > 0 || d != this.s) {
218
+ r[k++] = d;
219
+ }
220
+ }
221
+ }
222
+ return r;
223
+ };
224
+ // BigInteger.prototype.equals = bnEquals;
225
+ BigInteger.prototype.equals = function (a) {
226
+ return this.compareTo(a) == 0;
227
+ };
228
+ // BigInteger.prototype.min = bnMin;
229
+ BigInteger.prototype.min = function (a) {
230
+ return this.compareTo(a) < 0 ? this : a;
231
+ };
232
+ // BigInteger.prototype.max = bnMax;
233
+ BigInteger.prototype.max = function (a) {
234
+ return this.compareTo(a) > 0 ? this : a;
235
+ };
236
+ // BigInteger.prototype.and = bnAnd;
237
+ BigInteger.prototype.and = function (a) {
238
+ var r = nbi();
239
+ this.bitwiseTo(a, op_and, r);
240
+ return r;
241
+ };
242
+ // BigInteger.prototype.or = bnOr;
243
+ BigInteger.prototype.or = function (a) {
244
+ var r = nbi();
245
+ this.bitwiseTo(a, op_or, r);
246
+ return r;
247
+ };
248
+ // BigInteger.prototype.xor = bnXor;
249
+ BigInteger.prototype.xor = function (a) {
250
+ var r = nbi();
251
+ this.bitwiseTo(a, op_xor, r);
252
+ return r;
253
+ };
254
+ // BigInteger.prototype.andNot = bnAndNot;
255
+ BigInteger.prototype.andNot = function (a) {
256
+ var r = nbi();
257
+ this.bitwiseTo(a, op_andnot, r);
258
+ return r;
259
+ };
260
+ // BigInteger.prototype.not = bnNot;
261
+ // (public) ~this
262
+ BigInteger.prototype.not = function () {
263
+ var r = nbi();
264
+ for (var i = 0; i < this.t; ++i) {
265
+ r[i] = this.DM & ~this[i];
266
+ }
267
+ r.t = this.t;
268
+ r.s = ~this.s;
269
+ return r;
270
+ };
271
+ // BigInteger.prototype.shiftLeft = bnShiftLeft;
272
+ // (public) this << n
273
+ BigInteger.prototype.shiftLeft = function (n) {
274
+ var r = nbi();
275
+ if (n < 0) {
276
+ this.rShiftTo(-n, r);
277
+ } else {
278
+ this.lShiftTo(n, r);
279
+ }
280
+ return r;
281
+ };
282
+ // BigInteger.prototype.shiftRight = bnShiftRight;
283
+ // (public) this >> n
284
+ BigInteger.prototype.shiftRight = function (n) {
285
+ var r = nbi();
286
+ if (n < 0) {
287
+ this.lShiftTo(-n, r);
288
+ } else {
289
+ this.rShiftTo(n, r);
290
+ }
291
+ return r;
292
+ };
293
+ // BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
294
+ // (public) returns index of lowest 1-bit (or -1 if none)
295
+ BigInteger.prototype.getLowestSetBit = function () {
296
+ for (var i = 0; i < this.t; ++i) {
297
+ if (this[i] != 0) {
298
+ return i * this.DB + lbit(this[i]);
299
+ }
300
+ }
301
+ if (this.s < 0) {
302
+ return this.t * this.DB;
303
+ }
304
+ return -1;
305
+ };
306
+ // BigInteger.prototype.bitCount = bnBitCount;
307
+ // (public) return number of set bits
308
+ BigInteger.prototype.bitCount = function () {
309
+ var r = 0;
310
+ var x = this.s & this.DM;
311
+ for (var i = 0; i < this.t; ++i) {
312
+ r += cbit(this[i] ^ x);
313
+ }
314
+ return r;
315
+ };
316
+ // BigInteger.prototype.testBit = bnTestBit;
317
+ // (public) true iff nth bit is set
318
+ BigInteger.prototype.testBit = function (n) {
319
+ var j = Math.floor(n / this.DB);
320
+ if (j >= this.t) {
321
+ return this.s != 0;
322
+ }
323
+ return (this[j] & 1 << n % this.DB) != 0;
324
+ };
325
+ // BigInteger.prototype.setBit = bnSetBit;
326
+ // (public) this | (1<<n)
327
+ BigInteger.prototype.setBit = function (n) {
328
+ return this.changeBit(n, op_or);
329
+ };
330
+ // BigInteger.prototype.clearBit = bnClearBit;
331
+ // (public) this & ~(1<<n)
332
+ BigInteger.prototype.clearBit = function (n) {
333
+ return this.changeBit(n, op_andnot);
334
+ };
335
+ // BigInteger.prototype.flipBit = bnFlipBit;
336
+ // (public) this ^ (1<<n)
337
+ BigInteger.prototype.flipBit = function (n) {
338
+ return this.changeBit(n, op_xor);
339
+ };
340
+ // BigInteger.prototype.add = bnAdd;
341
+ // (public) this + a
342
+ BigInteger.prototype.add = function (a) {
343
+ var r = nbi();
344
+ this.addTo(a, r);
345
+ return r;
346
+ };
347
+ // BigInteger.prototype.subtract = bnSubtract;
348
+ // (public) this - a
349
+ BigInteger.prototype.subtract = function (a) {
350
+ var r = nbi();
351
+ this.subTo(a, r);
352
+ return r;
353
+ };
354
+ // BigInteger.prototype.multiply = bnMultiply;
355
+ // (public) this * a
356
+ BigInteger.prototype.multiply = function (a) {
357
+ var r = nbi();
358
+ this.multiplyTo(a, r);
359
+ return r;
360
+ };
361
+ // BigInteger.prototype.divide = bnDivide;
362
+ // (public) this / a
363
+ BigInteger.prototype.divide = function (a) {
364
+ var r = nbi();
365
+ this.divRemTo(a, r, null);
366
+ return r;
367
+ };
368
+ // BigInteger.prototype.remainder = bnRemainder;
369
+ // (public) this % a
370
+ BigInteger.prototype.remainder = function (a) {
371
+ var r = nbi();
372
+ this.divRemTo(a, null, r);
373
+ return r;
374
+ };
375
+ // BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
376
+ // (public) [this/a,this%a]
377
+ BigInteger.prototype.divideAndRemainder = function (a) {
378
+ var q = nbi();
379
+ var r = nbi();
380
+ this.divRemTo(a, q, r);
381
+ return [q, r];
382
+ };
383
+ // BigInteger.prototype.modPow = bnModPow;
384
+ // (public) this^e % m (HAC 14.85)
385
+ BigInteger.prototype.modPow = function (e, m) {
386
+ var i = e.bitLength();
387
+ var k;
388
+ var r = nbv(1);
389
+ var z;
390
+ if (i <= 0) {
391
+ return r;
392
+ } else if (i < 18) {
393
+ k = 1;
394
+ } else if (i < 48) {
395
+ k = 3;
396
+ } else if (i < 144) {
397
+ k = 4;
398
+ } else if (i < 768) {
399
+ k = 5;
400
+ } else {
401
+ k = 6;
402
+ }
403
+ if (i < 8) {
404
+ z = new Classic(m);
405
+ } else if (m.isEven()) {
406
+ z = new Barrett(m);
407
+ } else {
408
+ z = new Montgomery(m);
409
+ }
410
+ // precomputation
411
+ var g = [];
412
+ var n = 3;
413
+ var k1 = k - 1;
414
+ var km = (1 << k) - 1;
415
+ g[1] = z.convert(this);
416
+ if (k > 1) {
417
+ var g2 = nbi();
418
+ z.sqrTo(g[1], g2);
419
+ while (n <= km) {
420
+ g[n] = nbi();
421
+ z.mulTo(g2, g[n - 2], g[n]);
422
+ n += 2;
423
+ }
424
+ }
425
+ var j = e.t - 1;
426
+ var w;
427
+ var is1 = true;
428
+ var r2 = nbi();
429
+ var t;
430
+ i = nbits(e[j]) - 1;
431
+ while (j >= 0) {
432
+ if (i >= k1) {
433
+ w = e[j] >> i - k1 & km;
434
+ } else {
435
+ w = (e[j] & (1 << i + 1) - 1) << k1 - i;
436
+ if (j > 0) {
437
+ w |= e[j - 1] >> this.DB + i - k1;
438
+ }
439
+ }
440
+ n = k;
441
+ while ((w & 1) == 0) {
442
+ w >>= 1;
443
+ --n;
444
+ }
445
+ if ((i -= n) < 0) {
446
+ i += this.DB;
447
+ --j;
448
+ }
449
+ if (is1) {
450
+ // ret == 1, don't bother squaring or multiplying it
451
+ g[w].copyTo(r);
452
+ is1 = false;
453
+ } else {
454
+ while (n > 1) {
455
+ z.sqrTo(r, r2);
456
+ z.sqrTo(r2, r);
457
+ n -= 2;
458
+ }
459
+ if (n > 0) {
460
+ z.sqrTo(r, r2);
461
+ } else {
462
+ t = r;
463
+ r = r2;
464
+ r2 = t;
465
+ }
466
+ z.mulTo(r2, g[w], r);
467
+ }
468
+ while (j >= 0 && (e[j] & 1 << i) == 0) {
469
+ z.sqrTo(r, r2);
470
+ t = r;
471
+ r = r2;
472
+ r2 = t;
473
+ if (--i < 0) {
474
+ i = this.DB - 1;
475
+ --j;
476
+ }
477
+ }
478
+ }
479
+ return z.revert(r);
480
+ };
481
+ // BigInteger.prototype.modInverse = bnModInverse;
482
+ // (public) 1/this % m (HAC 14.61)
483
+ BigInteger.prototype.modInverse = function (m) {
484
+ var ac = m.isEven();
485
+ if (this.isEven() && ac || m.signum() == 0) {
486
+ return BigInteger.ZERO;
487
+ }
488
+ var u = m.clone();
489
+ var v = this.clone();
490
+ var a = nbv(1);
491
+ var b = nbv(0);
492
+ var c = nbv(0);
493
+ var d = nbv(1);
494
+ while (u.signum() != 0) {
495
+ while (u.isEven()) {
496
+ u.rShiftTo(1, u);
497
+ if (ac) {
498
+ if (!a.isEven() || !b.isEven()) {
499
+ a.addTo(this, a);
500
+ b.subTo(m, b);
501
+ }
502
+ a.rShiftTo(1, a);
503
+ } else if (!b.isEven()) {
504
+ b.subTo(m, b);
505
+ }
506
+ b.rShiftTo(1, b);
507
+ }
508
+ while (v.isEven()) {
509
+ v.rShiftTo(1, v);
510
+ if (ac) {
511
+ if (!c.isEven() || !d.isEven()) {
512
+ c.addTo(this, c);
513
+ d.subTo(m, d);
514
+ }
515
+ c.rShiftTo(1, c);
516
+ } else if (!d.isEven()) {
517
+ d.subTo(m, d);
518
+ }
519
+ d.rShiftTo(1, d);
520
+ }
521
+ if (u.compareTo(v) >= 0) {
522
+ u.subTo(v, u);
523
+ if (ac) {
524
+ a.subTo(c, a);
525
+ }
526
+ b.subTo(d, b);
527
+ } else {
528
+ v.subTo(u, v);
529
+ if (ac) {
530
+ c.subTo(a, c);
531
+ }
532
+ d.subTo(b, d);
533
+ }
534
+ }
535
+ if (v.compareTo(BigInteger.ONE) != 0) {
536
+ return BigInteger.ZERO;
537
+ }
538
+ if (d.compareTo(m) >= 0) {
539
+ return d.subtract(m);
540
+ }
541
+ if (d.signum() < 0) {
542
+ d.addTo(m, d);
543
+ } else {
544
+ return d;
545
+ }
546
+ if (d.signum() < 0) {
547
+ return d.add(m);
548
+ } else {
549
+ return d;
550
+ }
551
+ };
552
+ // BigInteger.prototype.pow = bnPow;
553
+ // (public) this^e
554
+ BigInteger.prototype.pow = function (e) {
555
+ return this.exp(e, new NullExp());
556
+ };
557
+ // BigInteger.prototype.gcd = bnGCD;
558
+ // (public) gcd(this,a) (HAC 14.54)
559
+ BigInteger.prototype.gcd = function (a) {
560
+ var x = this.s < 0 ? this.negate() : this.clone();
561
+ var y = a.s < 0 ? a.negate() : a.clone();
562
+ if (x.compareTo(y) < 0) {
563
+ var t = x;
564
+ x = y;
565
+ y = t;
566
+ }
567
+ var i = x.getLowestSetBit();
568
+ var g = y.getLowestSetBit();
569
+ if (g < 0) {
570
+ return x;
571
+ }
572
+ if (i < g) {
573
+ g = i;
574
+ }
575
+ if (g > 0) {
576
+ x.rShiftTo(g, x);
577
+ y.rShiftTo(g, y);
578
+ }
579
+ while (x.signum() > 0) {
580
+ if ((i = x.getLowestSetBit()) > 0) {
581
+ x.rShiftTo(i, x);
582
+ }
583
+ if ((i = y.getLowestSetBit()) > 0) {
584
+ y.rShiftTo(i, y);
585
+ }
586
+ if (x.compareTo(y) >= 0) {
587
+ x.subTo(y, x);
588
+ x.rShiftTo(1, x);
589
+ } else {
590
+ y.subTo(x, y);
591
+ y.rShiftTo(1, y);
592
+ }
593
+ }
594
+ if (g > 0) {
595
+ y.lShiftTo(g, y);
596
+ }
597
+ return y;
598
+ };
599
+ // BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
600
+ // (public) test primality with certainty >= 1-.5^t
601
+ BigInteger.prototype.isProbablePrime = function (t) {
602
+ var i;
603
+ var x = this.abs();
604
+ if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
605
+ for (i = 0; i < lowprimes.length; ++i) {
606
+ if (x[0] == lowprimes[i]) {
607
+ return true;
608
+ }
609
+ }
610
+ return false;
611
+ }
612
+ if (x.isEven()) {
613
+ return false;
614
+ }
615
+ i = 1;
616
+ while (i < lowprimes.length) {
617
+ var m = lowprimes[i];
618
+ var j = i + 1;
619
+ while (j < lowprimes.length && m < lplim) {
620
+ m *= lowprimes[j++];
621
+ }
622
+ m = x.modInt(m);
623
+ while (i < j) {
624
+ if (m % lowprimes[i++] == 0) {
625
+ return false;
626
+ }
627
+ }
628
+ }
629
+ return x.millerRabin(t);
630
+ };
631
+ //#endregion PUBLIC
632
+ //#region PROTECTED
633
+ // BigInteger.prototype.copyTo = bnpCopyTo;
634
+ // (protected) copy this to r
635
+ BigInteger.prototype.copyTo = function (r) {
636
+ for (var i = this.t - 1; i >= 0; --i) {
637
+ r[i] = this[i];
638
+ }
639
+ r.t = this.t;
640
+ r.s = this.s;
641
+ };
642
+ // BigInteger.prototype.fromInt = bnpFromInt;
643
+ // (protected) set from integer value x, -DV <= x < DV
644
+ BigInteger.prototype.fromInt = function (x) {
645
+ this.t = 1;
646
+ this.s = x < 0 ? -1 : 0;
647
+ if (x > 0) {
648
+ this[0] = x;
649
+ } else if (x < -1) {
650
+ this[0] = x + this.DV;
651
+ } else {
652
+ this.t = 0;
653
+ }
654
+ };
655
+ // BigInteger.prototype.fromString = bnpFromString;
656
+ // (protected) set from string and radix
657
+ BigInteger.prototype.fromString = function (s, b) {
658
+ var k;
659
+ if (b == 16) {
660
+ k = 4;
661
+ } else if (b == 8) {
662
+ k = 3;
663
+ } else if (b == 256) {
664
+ k = 8;
665
+ /* byte array */
666
+ } else if (b == 2) {
667
+ k = 1;
668
+ } else if (b == 32) {
669
+ k = 5;
670
+ } else if (b == 4) {
671
+ k = 2;
672
+ } else {
673
+ this.fromRadix(s, b);
674
+ return;
675
+ }
676
+ this.t = 0;
677
+ this.s = 0;
678
+ var i = s.length;
679
+ var mi = false;
680
+ var sh = 0;
681
+ while (--i >= 0) {
682
+ var x = k == 8 ? +s[i] & 0xff : intAt(s, i);
683
+ if (x < 0) {
684
+ if (s.charAt(i) == "-") {
685
+ mi = true;
686
+ }
687
+ continue;
688
+ }
689
+ mi = false;
690
+ if (sh == 0) {
691
+ this[this.t++] = x;
692
+ } else if (sh + k > this.DB) {
693
+ this[this.t - 1] |= (x & (1 << this.DB - sh) - 1) << sh;
694
+ this[this.t++] = x >> this.DB - sh;
695
+ } else {
696
+ this[this.t - 1] |= x << sh;
697
+ }
698
+ sh += k;
699
+ if (sh >= this.DB) {
700
+ sh -= this.DB;
701
+ }
702
+ }
703
+ if (k == 8 && (+s[0] & 0x80) != 0) {
704
+ this.s = -1;
705
+ if (sh > 0) {
706
+ this[this.t - 1] |= (1 << this.DB - sh) - 1 << sh;
707
+ }
708
+ }
709
+ this.clamp();
710
+ if (mi) {
711
+ BigInteger.ZERO.subTo(this, this);
712
+ }
713
+ };
714
+ // BigInteger.prototype.clamp = bnpClamp;
715
+ // (protected) clamp off excess high words
716
+ BigInteger.prototype.clamp = function () {
717
+ var c = this.s & this.DM;
718
+ while (this.t > 0 && this[this.t - 1] == c) {
719
+ --this.t;
720
+ }
721
+ };
722
+ // BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
723
+ // (protected) r = this << n*DB
724
+ BigInteger.prototype.dlShiftTo = function (n, r) {
725
+ var i;
726
+ for (i = this.t - 1; i >= 0; --i) {
727
+ r[i + n] = this[i];
728
+ }
729
+ for (i = n - 1; i >= 0; --i) {
730
+ r[i] = 0;
731
+ }
732
+ r.t = this.t + n;
733
+ r.s = this.s;
734
+ };
735
+ // BigInteger.prototype.drShiftTo = bnpDRShiftTo;
736
+ // (protected) r = this >> n*DB
737
+ BigInteger.prototype.drShiftTo = function (n, r) {
738
+ for (var i = n; i < this.t; ++i) {
739
+ r[i - n] = this[i];
740
+ }
741
+ r.t = Math.max(this.t - n, 0);
742
+ r.s = this.s;
743
+ };
744
+ // BigInteger.prototype.lShiftTo = bnpLShiftTo;
745
+ // (protected) r = this << n
746
+ BigInteger.prototype.lShiftTo = function (n, r) {
747
+ var bs = n % this.DB;
748
+ var cbs = this.DB - bs;
749
+ var bm = (1 << cbs) - 1;
750
+ var ds = Math.floor(n / this.DB);
751
+ var c = this.s << bs & this.DM;
752
+ for (var i = this.t - 1; i >= 0; --i) {
753
+ r[i + ds + 1] = this[i] >> cbs | c;
754
+ c = (this[i] & bm) << bs;
755
+ }
756
+ for (var i = ds - 1; i >= 0; --i) {
757
+ r[i] = 0;
758
+ }
759
+ r[ds] = c;
760
+ r.t = this.t + ds + 1;
761
+ r.s = this.s;
762
+ r.clamp();
763
+ };
764
+ // BigInteger.prototype.rShiftTo = bnpRShiftTo;
765
+ // (protected) r = this >> n
766
+ BigInteger.prototype.rShiftTo = function (n, r) {
767
+ r.s = this.s;
768
+ var ds = Math.floor(n / this.DB);
769
+ if (ds >= this.t) {
770
+ r.t = 0;
771
+ return;
772
+ }
773
+ var bs = n % this.DB;
774
+ var cbs = this.DB - bs;
775
+ var bm = (1 << bs) - 1;
776
+ r[0] = this[ds] >> bs;
777
+ for (var i = ds + 1; i < this.t; ++i) {
778
+ r[i - ds - 1] |= (this[i] & bm) << cbs;
779
+ r[i - ds] = this[i] >> bs;
780
+ }
781
+ if (bs > 0) {
782
+ r[this.t - ds - 1] |= (this.s & bm) << cbs;
783
+ }
784
+ r.t = this.t - ds;
785
+ r.clamp();
786
+ };
787
+ // BigInteger.prototype.subTo = bnpSubTo;
788
+ // (protected) r = this - a
789
+ BigInteger.prototype.subTo = function (a, r) {
790
+ var i = 0;
791
+ var c = 0;
792
+ var m = Math.min(a.t, this.t);
793
+ while (i < m) {
794
+ c += this[i] - a[i];
795
+ r[i++] = c & this.DM;
796
+ c >>= this.DB;
797
+ }
798
+ if (a.t < this.t) {
799
+ c -= a.s;
800
+ while (i < this.t) {
801
+ c += this[i];
802
+ r[i++] = c & this.DM;
803
+ c >>= this.DB;
804
+ }
805
+ c += this.s;
806
+ } else {
807
+ c += this.s;
808
+ while (i < a.t) {
809
+ c -= a[i];
810
+ r[i++] = c & this.DM;
811
+ c >>= this.DB;
812
+ }
813
+ c -= a.s;
814
+ }
815
+ r.s = c < 0 ? -1 : 0;
816
+ if (c < -1) {
817
+ r[i++] = this.DV + c;
818
+ } else if (c > 0) {
819
+ r[i++] = c;
820
+ }
821
+ r.t = i;
822
+ r.clamp();
823
+ };
824
+ // BigInteger.prototype.multiplyTo = bnpMultiplyTo;
825
+ // (protected) r = this * a, r != this,a (HAC 14.12)
826
+ // "this" should be the larger one if appropriate.
827
+ BigInteger.prototype.multiplyTo = function (a, r) {
828
+ var x = this.abs();
829
+ var y = a.abs();
830
+ var i = x.t;
831
+ r.t = i + y.t;
832
+ while (--i >= 0) {
833
+ r[i] = 0;
834
+ }
835
+ for (i = 0; i < y.t; ++i) {
836
+ r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
837
+ }
838
+ r.s = 0;
839
+ r.clamp();
840
+ if (this.s != a.s) {
841
+ BigInteger.ZERO.subTo(r, r);
842
+ }
843
+ };
844
+ // BigInteger.prototype.squareTo = bnpSquareTo;
845
+ // (protected) r = this^2, r != this (HAC 14.16)
846
+ BigInteger.prototype.squareTo = function (r) {
847
+ var x = this.abs();
848
+ var i = r.t = 2 * x.t;
849
+ while (--i >= 0) {
850
+ r[i] = 0;
851
+ }
852
+ for (i = 0; i < x.t - 1; ++i) {
853
+ var c = x.am(i, x[i], r, 2 * i, 0, 1);
854
+ if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
855
+ r[i + x.t] -= x.DV;
856
+ r[i + x.t + 1] = 1;
857
+ }
858
+ }
859
+ if (r.t > 0) {
860
+ r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
861
+ }
862
+ r.s = 0;
863
+ r.clamp();
864
+ };
865
+ // BigInteger.prototype.divRemTo = bnpDivRemTo;
866
+ // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
867
+ // r != q, this != m. q or r may be null.
868
+ BigInteger.prototype.divRemTo = function (m, q, r) {
869
+ var pm = m.abs();
870
+ if (pm.t <= 0) {
871
+ return;
872
+ }
873
+ var pt = this.abs();
874
+ if (pt.t < pm.t) {
875
+ if (q != null) {
876
+ q.fromInt(0);
877
+ }
878
+ if (r != null) {
879
+ this.copyTo(r);
880
+ }
881
+ return;
882
+ }
883
+ if (r == null) {
884
+ r = nbi();
885
+ }
886
+ var y = nbi();
887
+ var ts = this.s;
888
+ var ms = m.s;
889
+ var nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus
890
+ if (nsh > 0) {
891
+ pm.lShiftTo(nsh, y);
892
+ pt.lShiftTo(nsh, r);
893
+ } else {
894
+ pm.copyTo(y);
895
+ pt.copyTo(r);
896
+ }
897
+ var ys = y.t;
898
+ var y0 = y[ys - 1];
899
+ if (y0 == 0) {
900
+ return;
901
+ }
902
+ var yt = y0 * (1 << this.F1) + (ys > 1 ? y[ys - 2] >> this.F2 : 0);
903
+ var d1 = this.FV / yt;
904
+ var d2 = (1 << this.F1) / yt;
905
+ var e = 1 << this.F2;
906
+ var i = r.t;
907
+ var j = i - ys;
908
+ var t = q == null ? nbi() : q;
909
+ y.dlShiftTo(j, t);
910
+ if (r.compareTo(t) >= 0) {
911
+ r[r.t++] = 1;
912
+ r.subTo(t, r);
913
+ }
914
+ BigInteger.ONE.dlShiftTo(ys, t);
915
+ t.subTo(y, y); // "negative" y so we can replace sub with am later
916
+ while (y.t < ys) {
917
+ y[y.t++] = 0;
918
+ }
919
+ while (--j >= 0) {
920
+ // Estimate quotient digit
921
+ var qd = r[--i] == y0 ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
922
+ if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) {
923
+ // Try it out
924
+ y.dlShiftTo(j, t);
925
+ r.subTo(t, r);
926
+ while (r[i] < --qd) {
927
+ r.subTo(t, r);
928
+ }
929
+ }
930
+ }
931
+ if (q != null) {
932
+ r.drShiftTo(ys, q);
933
+ if (ts != ms) {
934
+ BigInteger.ZERO.subTo(q, q);
935
+ }
936
+ }
937
+ r.t = ys;
938
+ r.clamp();
939
+ if (nsh > 0) {
940
+ r.rShiftTo(nsh, r);
941
+ } // Denormalize remainder
942
+ if (ts < 0) {
943
+ BigInteger.ZERO.subTo(r, r);
944
+ }
945
+ };
946
+ // BigInteger.prototype.invDigit = bnpInvDigit;
947
+ // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
948
+ // justification:
949
+ // xy == 1 (mod m)
950
+ // xy = 1+km
951
+ // xy(2-xy) = (1+km)(1-km)
952
+ // x[y(2-xy)] = 1-k^2m^2
953
+ // x[y(2-xy)] == 1 (mod m^2)
954
+ // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
955
+ // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
956
+ // JS multiply "overflows" differently from C/C++, so care is needed here.
957
+ BigInteger.prototype.invDigit = function () {
958
+ if (this.t < 1) {
959
+ return 0;
960
+ }
961
+ var x = this[0];
962
+ if ((x & 1) == 0) {
963
+ return 0;
964
+ }
965
+ var y = x & 3; // y == 1/x mod 2^2
966
+ y = y * (2 - (x & 0xf) * y) & 0xf; // y == 1/x mod 2^4
967
+ y = y * (2 - (x & 0xff) * y) & 0xff; // y == 1/x mod 2^8
968
+ y = y * (2 - ((x & 0xffff) * y & 0xffff)) & 0xffff; // y == 1/x mod 2^16
969
+ // last step - calculate inverse mod DV directly;
970
+ // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
971
+ y = y * (2 - x * y % this.DV) % this.DV; // y == 1/x mod 2^dbits
972
+ // we really want the negative inverse, and -DV < y < DV
973
+ return y > 0 ? this.DV - y : -y;
974
+ };
975
+ // BigInteger.prototype.isEven = bnpIsEven;
976
+ // (protected) true iff this is even
977
+ BigInteger.prototype.isEven = function () {
978
+ return (this.t > 0 ? this[0] & 1 : this.s) == 0;
979
+ };
980
+ // BigInteger.prototype.exp = bnpExp;
981
+ // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
982
+ BigInteger.prototype.exp = function (e, z) {
983
+ if (e > 0xffffffff || e < 1) {
984
+ return BigInteger.ONE;
985
+ }
986
+ var r = nbi();
987
+ var r2 = nbi();
988
+ var g = z.convert(this);
989
+ var i = nbits(e) - 1;
990
+ g.copyTo(r);
991
+ while (--i >= 0) {
992
+ z.sqrTo(r, r2);
993
+ if ((e & 1 << i) > 0) {
994
+ z.mulTo(r2, g, r);
995
+ } else {
996
+ var t = r;
997
+ r = r2;
998
+ r2 = t;
999
+ }
1000
+ }
1001
+ return z.revert(r);
1002
+ };
1003
+ // BigInteger.prototype.chunkSize = bnpChunkSize;
1004
+ // (protected) return x s.t. r^x < DV
1005
+ BigInteger.prototype.chunkSize = function (r) {
1006
+ return Math.floor(Math.LN2 * this.DB / Math.log(r));
1007
+ };
1008
+ // BigInteger.prototype.toRadix = bnpToRadix;
1009
+ // (protected) convert to radix string
1010
+ BigInteger.prototype.toRadix = function (b) {
1011
+ if (b == null) {
1012
+ b = 10;
1013
+ }
1014
+ if (this.signum() == 0 || b < 2 || b > 36) {
1015
+ return "0";
1016
+ }
1017
+ var cs = this.chunkSize(b);
1018
+ var a = Math.pow(b, cs);
1019
+ var d = nbv(a);
1020
+ var y = nbi();
1021
+ var z = nbi();
1022
+ var r = "";
1023
+ this.divRemTo(d, y, z);
1024
+ while (y.signum() > 0) {
1025
+ r = (a + z.intValue()).toString(b).substring(1) + r;
1026
+ y.divRemTo(d, y, z);
1027
+ }
1028
+ return z.intValue().toString(b) + r;
1029
+ };
1030
+ // BigInteger.prototype.fromRadix = bnpFromRadix;
1031
+ // (protected) convert from radix string
1032
+ BigInteger.prototype.fromRadix = function (s, b) {
1033
+ this.fromInt(0);
1034
+ if (b == null) {
1035
+ b = 10;
1036
+ }
1037
+ var cs = this.chunkSize(b);
1038
+ var d = Math.pow(b, cs);
1039
+ var mi = false;
1040
+ var j = 0;
1041
+ var w = 0;
1042
+ for (var i = 0; i < s.length; ++i) {
1043
+ var x = intAt(s, i);
1044
+ if (x < 0) {
1045
+ if (s.charAt(i) == "-" && this.signum() == 0) {
1046
+ mi = true;
1047
+ }
1048
+ continue;
1049
+ }
1050
+ w = b * w + x;
1051
+ if (++j >= cs) {
1052
+ this.dMultiply(d);
1053
+ this.dAddOffset(w, 0);
1054
+ j = 0;
1055
+ w = 0;
1056
+ }
1057
+ }
1058
+ if (j > 0) {
1059
+ this.dMultiply(Math.pow(b, j));
1060
+ this.dAddOffset(w, 0);
1061
+ }
1062
+ if (mi) {
1063
+ BigInteger.ZERO.subTo(this, this);
1064
+ }
1065
+ };
1066
+ // BigInteger.prototype.fromNumber = bnpFromNumber;
1067
+ // (protected) alternate constructor
1068
+ BigInteger.prototype.fromNumber = function (a, b, c) {
1069
+ if ("number" == typeof b) {
1070
+ // new BigInteger(int,int,RNG)
1071
+ if (a < 2) {
1072
+ this.fromInt(1);
1073
+ } else {
1074
+ this.fromNumber(a, c);
1075
+ if (!this.testBit(a - 1)) {
1076
+ // force MSB set
1077
+ this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
1078
+ }
1079
+ if (this.isEven()) {
1080
+ this.dAddOffset(1, 0);
1081
+ } // force odd
1082
+ while (!this.isProbablePrime(b)) {
1083
+ this.dAddOffset(2, 0);
1084
+ if (this.bitLength() > a) {
1085
+ this.subTo(BigInteger.ONE.shiftLeft(a - 1), this);
1086
+ }
1087
+ }
1088
+ }
1089
+ } else {
1090
+ // new BigInteger(int,RNG)
1091
+ var x = [];
1092
+ var t = a & 7;
1093
+ x.length = (a >> 3) + 1;
1094
+ b.nextBytes(x);
1095
+ if (t > 0) {
1096
+ x[0] &= (1 << t) - 1;
1097
+ } else {
1098
+ x[0] = 0;
1099
+ }
1100
+ this.fromString(x, 256);
1101
+ }
1102
+ };
1103
+ // BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
1104
+ // (protected) r = this op a (bitwise)
1105
+ BigInteger.prototype.bitwiseTo = function (a, op, r) {
1106
+ var i;
1107
+ var f;
1108
+ var m = Math.min(a.t, this.t);
1109
+ for (i = 0; i < m; ++i) {
1110
+ r[i] = op(this[i], a[i]);
1111
+ }
1112
+ if (a.t < this.t) {
1113
+ f = a.s & this.DM;
1114
+ for (i = m; i < this.t; ++i) {
1115
+ r[i] = op(this[i], f);
1116
+ }
1117
+ r.t = this.t;
1118
+ } else {
1119
+ f = this.s & this.DM;
1120
+ for (i = m; i < a.t; ++i) {
1121
+ r[i] = op(f, a[i]);
1122
+ }
1123
+ r.t = a.t;
1124
+ }
1125
+ r.s = op(this.s, a.s);
1126
+ r.clamp();
1127
+ };
1128
+ // BigInteger.prototype.changeBit = bnpChangeBit;
1129
+ // (protected) this op (1<<n)
1130
+ BigInteger.prototype.changeBit = function (n, op) {
1131
+ var r = BigInteger.ONE.shiftLeft(n);
1132
+ this.bitwiseTo(r, op, r);
1133
+ return r;
1134
+ };
1135
+ // BigInteger.prototype.addTo = bnpAddTo;
1136
+ // (protected) r = this + a
1137
+ BigInteger.prototype.addTo = function (a, r) {
1138
+ var i = 0;
1139
+ var c = 0;
1140
+ var m = Math.min(a.t, this.t);
1141
+ while (i < m) {
1142
+ c += this[i] + a[i];
1143
+ r[i++] = c & this.DM;
1144
+ c >>= this.DB;
1145
+ }
1146
+ if (a.t < this.t) {
1147
+ c += a.s;
1148
+ while (i < this.t) {
1149
+ c += this[i];
1150
+ r[i++] = c & this.DM;
1151
+ c >>= this.DB;
1152
+ }
1153
+ c += this.s;
1154
+ } else {
1155
+ c += this.s;
1156
+ while (i < a.t) {
1157
+ c += a[i];
1158
+ r[i++] = c & this.DM;
1159
+ c >>= this.DB;
1160
+ }
1161
+ c += a.s;
1162
+ }
1163
+ r.s = c < 0 ? -1 : 0;
1164
+ if (c > 0) {
1165
+ r[i++] = c;
1166
+ } else if (c < -1) {
1167
+ r[i++] = this.DV + c;
1168
+ }
1169
+ r.t = i;
1170
+ r.clamp();
1171
+ };
1172
+ // BigInteger.prototype.dMultiply = bnpDMultiply;
1173
+ // (protected) this *= n, this >= 0, 1 < n < DV
1174
+ BigInteger.prototype.dMultiply = function (n) {
1175
+ this[this.t] = this.am(0, n - 1, this, 0, 0, this.t);
1176
+ ++this.t;
1177
+ this.clamp();
1178
+ };
1179
+ // BigInteger.prototype.dAddOffset = bnpDAddOffset;
1180
+ // (protected) this += n << w words, this >= 0
1181
+ BigInteger.prototype.dAddOffset = function (n, w) {
1182
+ if (n == 0) {
1183
+ return;
1184
+ }
1185
+ while (this.t <= w) {
1186
+ this[this.t++] = 0;
1187
+ }
1188
+ this[w] += n;
1189
+ while (this[w] >= this.DV) {
1190
+ this[w] -= this.DV;
1191
+ if (++w >= this.t) {
1192
+ this[this.t++] = 0;
1193
+ }
1194
+ ++this[w];
1195
+ }
1196
+ };
1197
+ // BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
1198
+ // (protected) r = lower n words of "this * a", a.t <= n
1199
+ // "this" should be the larger one if appropriate.
1200
+ BigInteger.prototype.multiplyLowerTo = function (a, n, r) {
1201
+ var i = Math.min(this.t + a.t, n);
1202
+ r.s = 0; // assumes a,this >= 0
1203
+ r.t = i;
1204
+ while (i > 0) {
1205
+ r[--i] = 0;
1206
+ }
1207
+ for (var j = r.t - this.t; i < j; ++i) {
1208
+ r[i + this.t] = this.am(0, a[i], r, i, 0, this.t);
1209
+ }
1210
+ for (var j = Math.min(a.t, n); i < j; ++i) {
1211
+ this.am(0, a[i], r, i, 0, n - i);
1212
+ }
1213
+ r.clamp();
1214
+ };
1215
+ // BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
1216
+ // (protected) r = "this * a" without lower n words, n > 0
1217
+ // "this" should be the larger one if appropriate.
1218
+ BigInteger.prototype.multiplyUpperTo = function (a, n, r) {
1219
+ --n;
1220
+ var i = r.t = this.t + a.t - n;
1221
+ r.s = 0; // assumes a,this >= 0
1222
+ while (--i >= 0) {
1223
+ r[i] = 0;
1224
+ }
1225
+ for (i = Math.max(n - this.t, 0); i < a.t; ++i) {
1226
+ r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n);
1227
+ }
1228
+ r.clamp();
1229
+ r.drShiftTo(1, r);
1230
+ };
1231
+ // BigInteger.prototype.modInt = bnpModInt;
1232
+ // (protected) this % n, n < 2^26
1233
+ BigInteger.prototype.modInt = function (n) {
1234
+ if (n <= 0) {
1235
+ return 0;
1236
+ }
1237
+ var d = this.DV % n;
1238
+ var r = this.s < 0 ? n - 1 : 0;
1239
+ if (this.t > 0) {
1240
+ if (d == 0) {
1241
+ r = this[0] % n;
1242
+ } else {
1243
+ for (var i = this.t - 1; i >= 0; --i) {
1244
+ r = (d * r + this[i]) % n;
1245
+ }
1246
+ }
1247
+ }
1248
+ return r;
1249
+ };
1250
+ // BigInteger.prototype.millerRabin = bnpMillerRabin;
1251
+ // (protected) true if probably prime (HAC 4.24, Miller-Rabin)
1252
+ BigInteger.prototype.millerRabin = function (t) {
1253
+ var n1 = this.subtract(BigInteger.ONE);
1254
+ var k = n1.getLowestSetBit();
1255
+ if (k <= 0) {
1256
+ return false;
1257
+ }
1258
+ var r = n1.shiftRight(k);
1259
+ t = t + 1 >> 1;
1260
+ if (t > lowprimes.length) {
1261
+ t = lowprimes.length;
1262
+ }
1263
+ var a = nbi();
1264
+ for (var i = 0; i < t; ++i) {
1265
+ // Pick bases at random, instead of starting at 2
1266
+ a.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]);
1267
+ var y = a.modPow(r, this);
1268
+ if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
1269
+ var j = 1;
1270
+ while (j++ < k && y.compareTo(n1) != 0) {
1271
+ y = y.modPowInt(2, this);
1272
+ if (y.compareTo(BigInteger.ONE) == 0) {
1273
+ return false;
1274
+ }
1275
+ }
1276
+ if (y.compareTo(n1) != 0) {
1277
+ return false;
1278
+ }
1279
+ }
1280
+ }
1281
+ return true;
1282
+ };
1283
+ // BigInteger.prototype.square = bnSquare;
1284
+ // (public) this^2
1285
+ BigInteger.prototype.square = function () {
1286
+ var r = nbi();
1287
+ this.squareTo(r);
1288
+ return r;
1289
+ };
1290
+ //#region ASYNC
1291
+ // Public API method
1292
+ BigInteger.prototype.gcda = function (a, callback) {
1293
+ var x = this.s < 0 ? this.negate() : this.clone();
1294
+ var y = a.s < 0 ? a.negate() : a.clone();
1295
+ if (x.compareTo(y) < 0) {
1296
+ var t = x;
1297
+ x = y;
1298
+ y = t;
1299
+ }
1300
+ var i = x.getLowestSetBit();
1301
+ var g = y.getLowestSetBit();
1302
+ if (g < 0) {
1303
+ callback(x);
1304
+ return;
1305
+ }
1306
+ if (i < g) {
1307
+ g = i;
1308
+ }
1309
+ if (g > 0) {
1310
+ x.rShiftTo(g, x);
1311
+ y.rShiftTo(g, y);
1312
+ }
1313
+ // Workhorse of the algorithm, gets called 200 - 800 times per 512 bit keygen.
1314
+ var gcda1 = function () {
1315
+ if ((i = x.getLowestSetBit()) > 0) {
1316
+ x.rShiftTo(i, x);
1317
+ }
1318
+ if ((i = y.getLowestSetBit()) > 0) {
1319
+ y.rShiftTo(i, y);
1320
+ }
1321
+ if (x.compareTo(y) >= 0) {
1322
+ x.subTo(y, x);
1323
+ x.rShiftTo(1, x);
1324
+ } else {
1325
+ y.subTo(x, y);
1326
+ y.rShiftTo(1, y);
1327
+ }
1328
+ if (!(x.signum() > 0)) {
1329
+ if (g > 0) {
1330
+ y.lShiftTo(g, y);
1331
+ }
1332
+ setTimeout(function () {
1333
+ callback(y);
1334
+ }, 0); // escape
1335
+ } else {
1336
+ setTimeout(gcda1, 0);
1337
+ }
1338
+ };
1339
+ setTimeout(gcda1, 10);
1340
+ };
1341
+ // (protected) alternate constructor
1342
+ BigInteger.prototype.fromNumberAsync = function (a, b, c, callback) {
1343
+ if ("number" == typeof b) {
1344
+ if (a < 2) {
1345
+ this.fromInt(1);
1346
+ } else {
1347
+ this.fromNumber(a, c);
1348
+ if (!this.testBit(a - 1)) {
1349
+ this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
1350
+ }
1351
+ if (this.isEven()) {
1352
+ this.dAddOffset(1, 0);
1353
+ }
1354
+ var bnp_1 = this;
1355
+ var bnpfn1_1 = function () {
1356
+ bnp_1.dAddOffset(2, 0);
1357
+ if (bnp_1.bitLength() > a) {
1358
+ bnp_1.subTo(BigInteger.ONE.shiftLeft(a - 1), bnp_1);
1359
+ }
1360
+ if (bnp_1.isProbablePrime(b)) {
1361
+ setTimeout(function () {
1362
+ callback();
1363
+ }, 0); // escape
1364
+ } else {
1365
+ setTimeout(bnpfn1_1, 0);
1366
+ }
1367
+ };
1368
+ setTimeout(bnpfn1_1, 0);
1369
+ }
1370
+ } else {
1371
+ var x = [];
1372
+ var t = a & 7;
1373
+ x.length = (a >> 3) + 1;
1374
+ b.nextBytes(x);
1375
+ if (t > 0) {
1376
+ x[0] &= (1 << t) - 1;
1377
+ } else {
1378
+ x[0] = 0;
1379
+ }
1380
+ this.fromString(x, 256);
1381
+ }
1382
+ };
1383
+ return BigInteger;
1384
+ }();
1385
+ //#region REDUCERS
1386
+ //#region NullExp
1387
+ var NullExp = /** @class */function () {
1388
+ function NullExp() {}
1389
+ // NullExp.prototype.convert = nNop;
1390
+ NullExp.prototype.convert = function (x) {
1391
+ return x;
1392
+ };
1393
+ // NullExp.prototype.revert = nNop;
1394
+ NullExp.prototype.revert = function (x) {
1395
+ return x;
1396
+ };
1397
+ // NullExp.prototype.mulTo = nMulTo;
1398
+ NullExp.prototype.mulTo = function (x, y, r) {
1399
+ x.multiplyTo(y, r);
1400
+ };
1401
+ // NullExp.prototype.sqrTo = nSqrTo;
1402
+ NullExp.prototype.sqrTo = function (x, r) {
1403
+ x.squareTo(r);
1404
+ };
1405
+ return NullExp;
1406
+ }();
1407
+ // Modular reduction using "classic" algorithm
1408
+ var Classic = /** @class */function () {
1409
+ function Classic(m) {
1410
+ this.m = m;
1411
+ }
1412
+ // Classic.prototype.convert = cConvert;
1413
+ Classic.prototype.convert = function (x) {
1414
+ if (x.s < 0 || x.compareTo(this.m) >= 0) {
1415
+ return x.mod(this.m);
1416
+ } else {
1417
+ return x;
1418
+ }
1419
+ };
1420
+ // Classic.prototype.revert = cRevert;
1421
+ Classic.prototype.revert = function (x) {
1422
+ return x;
1423
+ };
1424
+ // Classic.prototype.reduce = cReduce;
1425
+ Classic.prototype.reduce = function (x) {
1426
+ x.divRemTo(this.m, null, x);
1427
+ };
1428
+ // Classic.prototype.mulTo = cMulTo;
1429
+ Classic.prototype.mulTo = function (x, y, r) {
1430
+ x.multiplyTo(y, r);
1431
+ this.reduce(r);
1432
+ };
1433
+ // Classic.prototype.sqrTo = cSqrTo;
1434
+ Classic.prototype.sqrTo = function (x, r) {
1435
+ x.squareTo(r);
1436
+ this.reduce(r);
1437
+ };
1438
+ return Classic;
1439
+ }();
1440
+ //#endregion
1441
+ //#region Montgomery
1442
+ // Montgomery reduction
1443
+ var Montgomery = /** @class */function () {
1444
+ function Montgomery(m) {
1445
+ this.m = m;
1446
+ this.mp = m.invDigit();
1447
+ this.mpl = this.mp & 0x7fff;
1448
+ this.mph = this.mp >> 15;
1449
+ this.um = (1 << m.DB - 15) - 1;
1450
+ this.mt2 = 2 * m.t;
1451
+ }
1452
+ // Montgomery.prototype.convert = montConvert;
1453
+ // xR mod m
1454
+ Montgomery.prototype.convert = function (x) {
1455
+ var r = nbi();
1456
+ x.abs().dlShiftTo(this.m.t, r);
1457
+ r.divRemTo(this.m, null, r);
1458
+ if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
1459
+ this.m.subTo(r, r);
1460
+ }
1461
+ return r;
1462
+ };
1463
+ // Montgomery.prototype.revert = montRevert;
1464
+ // x/R mod m
1465
+ Montgomery.prototype.revert = function (x) {
1466
+ var r = nbi();
1467
+ x.copyTo(r);
1468
+ this.reduce(r);
1469
+ return r;
1470
+ };
1471
+ // Montgomery.prototype.reduce = montReduce;
1472
+ // x = x/R mod m (HAC 14.32)
1473
+ Montgomery.prototype.reduce = function (x) {
1474
+ while (x.t <= this.mt2) {
1475
+ // pad x so am has enough room later
1476
+ x[x.t++] = 0;
1477
+ }
1478
+ for (var i = 0; i < this.m.t; ++i) {
1479
+ // faster way of calculating u0 = x[i]*mp mod DV
1480
+ var j = x[i] & 0x7fff;
1481
+ var u0 = j * this.mpl + ((j * this.mph + (x[i] >> 15) * this.mpl & this.um) << 15) & x.DM;
1482
+ // use am to combine the multiply-shift-add into one call
1483
+ j = i + this.m.t;
1484
+ x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
1485
+ // propagate carry
1486
+ while (x[j] >= x.DV) {
1487
+ x[j] -= x.DV;
1488
+ x[++j]++;
1489
+ }
1490
+ }
1491
+ x.clamp();
1492
+ x.drShiftTo(this.m.t, x);
1493
+ if (x.compareTo(this.m) >= 0) {
1494
+ x.subTo(this.m, x);
1495
+ }
1496
+ };
1497
+ // Montgomery.prototype.mulTo = montMulTo;
1498
+ // r = "xy/R mod m"; x,y != r
1499
+ Montgomery.prototype.mulTo = function (x, y, r) {
1500
+ x.multiplyTo(y, r);
1501
+ this.reduce(r);
1502
+ };
1503
+ // Montgomery.prototype.sqrTo = montSqrTo;
1504
+ // r = "x^2/R mod m"; x != r
1505
+ Montgomery.prototype.sqrTo = function (x, r) {
1506
+ x.squareTo(r);
1507
+ this.reduce(r);
1508
+ };
1509
+ return Montgomery;
1510
+ }();
1511
+ //#endregion Montgomery
1512
+ //#region Barrett
1513
+ // Barrett modular reduction
1514
+ var Barrett = /** @class */function () {
1515
+ function Barrett(m) {
1516
+ this.m = m;
1517
+ // setup Barrett
1518
+ this.r2 = nbi();
1519
+ this.q3 = nbi();
1520
+ BigInteger.ONE.dlShiftTo(2 * m.t, this.r2);
1521
+ this.mu = this.r2.divide(m);
1522
+ }
1523
+ // Barrett.prototype.convert = barrettConvert;
1524
+ Barrett.prototype.convert = function (x) {
1525
+ if (x.s < 0 || x.t > 2 * this.m.t) {
1526
+ return x.mod(this.m);
1527
+ } else if (x.compareTo(this.m) < 0) {
1528
+ return x;
1529
+ } else {
1530
+ var r = nbi();
1531
+ x.copyTo(r);
1532
+ this.reduce(r);
1533
+ return r;
1534
+ }
1535
+ };
1536
+ // Barrett.prototype.revert = barrettRevert;
1537
+ Barrett.prototype.revert = function (x) {
1538
+ return x;
1539
+ };
1540
+ // Barrett.prototype.reduce = barrettReduce;
1541
+ // x = x mod m (HAC 14.42)
1542
+ Barrett.prototype.reduce = function (x) {
1543
+ x.drShiftTo(this.m.t - 1, this.r2);
1544
+ if (x.t > this.m.t + 1) {
1545
+ x.t = this.m.t + 1;
1546
+ x.clamp();
1547
+ }
1548
+ this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3);
1549
+ this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2);
1550
+ while (x.compareTo(this.r2) < 0) {
1551
+ x.dAddOffset(1, this.m.t + 1);
1552
+ }
1553
+ x.subTo(this.r2, x);
1554
+ while (x.compareTo(this.m) >= 0) {
1555
+ x.subTo(this.m, x);
1556
+ }
1557
+ };
1558
+ // Barrett.prototype.mulTo = barrettMulTo;
1559
+ // r = x*y mod m; x,y != r
1560
+ Barrett.prototype.mulTo = function (x, y, r) {
1561
+ x.multiplyTo(y, r);
1562
+ this.reduce(r);
1563
+ };
1564
+ // Barrett.prototype.sqrTo = barrettSqrTo;
1565
+ // r = x^2 mod m; x != r
1566
+ Barrett.prototype.sqrTo = function (x, r) {
1567
+ x.squareTo(r);
1568
+ this.reduce(r);
1569
+ };
1570
+ return Barrett;
1571
+ }();
1572
+ //#endregion
1573
+ //#endregion REDUCERS
1574
+ // return new, unset BigInteger
1575
+ function nbi() {
1576
+ return new BigInteger(null);
1577
+ }
1578
+ function parseBigInt(str, r) {
1579
+ return new BigInteger(str, r);
1580
+ }
1581
+ // am: Compute w_j += (x*this_i), propagate carries,
1582
+ // c is initial carry, returns final carry.
1583
+ // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
1584
+ // We need to select the fastest one that works in this environment.
1585
+ var inBrowser = typeof navigator !== "undefined";
1586
+ if (inBrowser && j_lm && navigator.appName == "Microsoft Internet Explorer") {
1587
+ // am2 avoids a big mult-and-extract completely.
1588
+ // Max digit bits should be <= 30 because we do bitwise ops
1589
+ // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
1590
+ BigInteger.prototype.am = function am2(i, x, w, j, c, n) {
1591
+ var xl = x & 0x7fff;
1592
+ var xh = x >> 15;
1593
+ while (--n >= 0) {
1594
+ var l = this[i] & 0x7fff;
1595
+ var h = this[i++] >> 15;
1596
+ var m = xh * l + h * xl;
1597
+ l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff);
1598
+ c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30);
1599
+ w[j++] = l & 0x3fffffff;
1600
+ }
1601
+ return c;
1602
+ };
1603
+ dbits = 30;
1604
+ } else if (inBrowser && j_lm && navigator.appName != "Netscape") {
1605
+ // am1: use a single mult and divide to get the high bits,
1606
+ // max digit bits should be 26 because
1607
+ // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
1608
+ BigInteger.prototype.am = function am1(i, x, w, j, c, n) {
1609
+ while (--n >= 0) {
1610
+ var v = x * this[i++] + w[j] + c;
1611
+ c = Math.floor(v / 0x4000000);
1612
+ w[j++] = v & 0x3ffffff;
1613
+ }
1614
+ return c;
1615
+ };
1616
+ dbits = 26;
1617
+ } else {
1618
+ // Mozilla/Netscape seems to prefer am3
1619
+ // Alternately, set max digit bits to 28 since some
1620
+ // browsers slow down when dealing with 32-bit numbers.
1621
+ BigInteger.prototype.am = function am3(i, x, w, j, c, n) {
1622
+ var xl = x & 0x3fff;
1623
+ var xh = x >> 14;
1624
+ while (--n >= 0) {
1625
+ var l = this[i] & 0x3fff;
1626
+ var h = this[i++] >> 14;
1627
+ var m = xh * l + h * xl;
1628
+ l = xl * l + ((m & 0x3fff) << 14) + w[j] + c;
1629
+ c = (l >> 28) + (m >> 14) + xh * h;
1630
+ w[j++] = l & 0xfffffff;
1631
+ }
1632
+ return c;
1633
+ };
1634
+ dbits = 28;
1635
+ }
1636
+ BigInteger.prototype.DB = dbits;
1637
+ BigInteger.prototype.DM = (1 << dbits) - 1;
1638
+ BigInteger.prototype.DV = 1 << dbits;
1639
+ var BI_FP = 52;
1640
+ BigInteger.prototype.FV = Math.pow(2, BI_FP);
1641
+ BigInteger.prototype.F1 = BI_FP - dbits;
1642
+ BigInteger.prototype.F2 = 2 * dbits - BI_FP;
1643
+ // Digit conversions
1644
+ var BI_RC = [];
1645
+ var rr;
1646
+ var vv;
1647
+ rr = "0".charCodeAt(0);
1648
+ for (vv = 0; vv <= 9; ++vv) {
1649
+ BI_RC[rr++] = vv;
1650
+ }
1651
+ rr = "a".charCodeAt(0);
1652
+ for (vv = 10; vv < 36; ++vv) {
1653
+ BI_RC[rr++] = vv;
1654
+ }
1655
+ rr = "A".charCodeAt(0);
1656
+ for (vv = 10; vv < 36; ++vv) {
1657
+ BI_RC[rr++] = vv;
1658
+ }
1659
+ function intAt(s, i) {
1660
+ var c = BI_RC[s.charCodeAt(i)];
1661
+ return c == null ? -1 : c;
1662
+ }
1663
+ // return bigint initialized to value
1664
+ function nbv(i) {
1665
+ var r = nbi();
1666
+ r.fromInt(i);
1667
+ return r;
1668
+ }
1669
+ // returns bit length of the integer x
1670
+ function nbits(x) {
1671
+ var r = 1;
1672
+ var t;
1673
+ if ((t = x >>> 16) != 0) {
1674
+ x = t;
1675
+ r += 16;
1676
+ }
1677
+ if ((t = x >> 8) != 0) {
1678
+ x = t;
1679
+ r += 8;
1680
+ }
1681
+ if ((t = x >> 4) != 0) {
1682
+ x = t;
1683
+ r += 4;
1684
+ }
1685
+ if ((t = x >> 2) != 0) {
1686
+ x = t;
1687
+ r += 2;
1688
+ }
1689
+ if ((t = x >> 1) != 0) {
1690
+ x = t;
1691
+ r += 1;
1692
+ }
1693
+ return r;
1694
+ }
1695
+ // "constants"
1696
+ BigInteger.ZERO = nbv(0);
1697
+ BigInteger.ONE = nbv(1);
1698
+
1699
+ export { BigInteger, intAt, nbi, nbits, nbv, parseBigInt };
1700
+ //# sourceMappingURL=jsbn.js.map