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