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