@ivujs/i-utils 1.1.1 → 1.1.2

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