@ivujs/i-utils 1.1.16 → 1.1.17

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