Created
July 19, 2022 13:17
-
-
Save wmealing/800fee746dc37ccb88b73e823ef85829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dbits, canary = 244837814094590, j_lm = 15715070 == (canary & 16777215); | |
function BigInteger(a, b, c) { | |
null != a && ("number" == typeof a ? this.fromNumber(a, b, c) : null == b && "string" != typeof a ? this.fromString(a, 256) : this.fromString(a, b)); | |
} | |
function nbi() { | |
return new BigInteger(null); | |
} | |
function am1(a, b, c, d, e, f) { | |
for (; 0 <= --f;) { | |
var h = b * this[a++] + c[d] + e; | |
e = Math.floor(h / 67108864); | |
c[d++] = h & 67108863; | |
} | |
return e; | |
} | |
function am2(a, b, c, d, e, f) { | |
var h = b & 32767; | |
for (b >>= 15; 0 <= --f;) { | |
var g = this[a] & 32767, l = this[a++] >> 15, n = b * g + l * h, g = h * g + ((n & 32767) << 15) + c[d] + (e & 1073741823); | |
e = (g >>> 30) + (n >>> 15) + b * l + (e >>> 30); | |
c[d++] = g & 1073741823; | |
} | |
return e; | |
} | |
function am3(a, b, c, d, e, f) { | |
var h = b & 16383; | |
for (b >>= 14; 0 <= --f;) { | |
var g = this[a] & 16383, l = this[a++] >> 14, n = b * g + l * h, g = h * g + ((n & 16383) << 14) + c[d] + e; | |
e = (g >> 28) + (n >> 14) + b * l; | |
c[d++] = g & 268435455; | |
} | |
return e; | |
} | |
j_lm && "Microsoft Internet Explorer" == navigator.appName ? (BigInteger.prototype.am = am2, dbits = 30) : j_lm && "Netscape" != navigator.appName ? (BigInteger.prototype.am = am1, dbits = 26) : (BigInteger.prototype.am = am3, dbits = 28); | |
BigInteger.prototype.DB = dbits; | |
BigInteger.prototype.DM = (1 << dbits) - 1; | |
BigInteger.prototype.DV = 1 << dbits; | |
var BI_FP = 52; | |
BigInteger.prototype.FV = Math.pow(2, BI_FP); | |
BigInteger.prototype.F1 = BI_FP - dbits; | |
BigInteger.prototype.F2 = 2 * dbits - BI_FP; | |
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz", BI_RC = [], rr, vv; | |
rr = 48; | |
for (vv = 0; 9 >= vv; ++vv) BI_RC[rr++] = vv; | |
rr = 97; | |
for (vv = 10; 36 > vv; ++vv) BI_RC[rr++] = vv; | |
rr = 65; | |
for (vv = 10; 36 > vv; ++vv) BI_RC[rr++] = vv; | |
function intAt(a, b) { | |
var c = BI_RC[a.charCodeAt(b)]; | |
return null == c ? -1 : c; | |
} | |
function bnpCopyTo(a) { | |
for (var b = this.t - 1; 0 <= b; --b) a[b] = this[b]; | |
a.t = this.t; | |
a.s = this.s; | |
} | |
function bnpFromInt(a) { | |
this.t = 1; | |
this.s = 0 > a ? -1 : 0; | |
0 < a ? this[0] = a : -1 > a ? this[0] = a + this.DV : this.t = 0; | |
} | |
function nbv(a) { | |
var b = nbi(); | |
b.fromInt(a); | |
return b; | |
} | |
function bnpFromString(a, b) { | |
var c; | |
if (16 == b) c = 4; else if (8 == b) c = 3; else if (256 == b) c = 8; else if (2 == b) c = 1; else if (32 == b) c = 5; else if (4 == b) c = 2; else { | |
this.fromRadix(a, b); | |
return; | |
} | |
this.s = this.t = 0; | |
for (var d = a.length, e = false, f = 0; 0 <= --d;) { | |
var h = 8 == c ? a[d] & 255 : intAt(a, d); | |
0 > h ? "-" == a.charAt(d) && (e = true) : (e = false, 0 == f ? this[this.t++] = h : f + c > this.DB ? (this[this.t - 1] |= (h & (1 << this.DB - f) - 1) << f, this[this.t++] = h >> this.DB - f) : this[this.t - 1] |= h << f, f += c, f >= this.DB && (f -= this.DB)); | |
} | |
8 == c && 0 != (a[0] & 128) && (this.s = -1, 0 < f && (this[this.t - 1] |= (1 << this.DB - f) - 1 << f)); | |
this.clamp(); | |
e && BigInteger.ZERO.subTo(this, this); | |
} | |
function bnpClamp() { | |
for (var a = this.s & this.DM; 0 < this.t && this[this.t - 1] == a;) --this.t; | |
} | |
function bnToString(a) { | |
if (0 > this.s) return "-" + this.negate().toString(a); | |
if (16 == a) a = 4; else if (8 == a) a = 3; else if (2 == a) a = 1; else if (32 == a) a = 5; else if (4 == a) a = 2; else return this.toRadix(a); | |
var b = (1 << a) - 1, c, d = false, e = "", f = this.t, h = this.DB - f * this.DB % a; | |
if (0 < f--) { | |
if (h < this.DB && 0 < (c = this[f] >> h)) d = true, e = BI_RM.charAt(c); | |
for (; 0 <= f;) h < a ? (c = (this[f] & (1 << h) - 1) << a - h, c |= this[--f] >> (h += this.DB - a)) : (c = this[f] >> (h -= a) & b, 0 >= h && (h += this.DB, --f)), 0 < c && (d = true), d && (e += BI_RM.charAt(c)); | |
} | |
return d ? e : "0"; | |
} | |
function bnNegate() { | |
var a = nbi(); | |
BigInteger.ZERO.subTo(this, a); | |
return a; | |
} | |
function bnAbs() { | |
return 0 > this.s ? this.negate() : this; | |
} | |
function bnCompareTo(a) { | |
var b = this.s - a.s; | |
if (0 != b) return b; | |
var c = this.t, b = c - a.t; | |
if (0 != b) return 0 > this.s ? -b : b; | |
for (; 0 <= --c;) if (0 != (b = this[c] - a[c])) return b; | |
return 0; | |
} | |
function nbits(a) { | |
var b = 1, c; | |
if (0 != (c = a >>> 16)) a = c, b += 16; | |
if (0 != (c = a >> 8)) a = c, b += 8; | |
if (0 != (c = a >> 4)) a = c, b += 4; | |
if (0 != (c = a >> 2)) a = c, b += 2; | |
0 != a >> 1 && (b += 1); | |
return b; | |
} | |
function bnBitLength() { | |
return 0 >= this.t ? 0 : this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ this.s & this.DM); | |
} | |
function bnpDLShiftTo(a, b) { | |
var c; | |
for (c = this.t - 1; 0 <= c; --c) b[c + a] = this[c]; | |
for (c = a - 1; 0 <= c; --c) b[c] = 0; | |
b.t = this.t + a; | |
b.s = this.s; | |
} | |
function bnpDRShiftTo(a, b) { | |
for (var c = a; c < this.t; ++c) b[c - a] = this[c]; | |
b.t = Math.max(this.t - a, 0); | |
b.s = this.s; | |
} | |
function bnpLShiftTo(a, b) { | |
var c = a % this.DB, d = this.DB - c, e = (1 << d) - 1, f = Math.floor(a / this.DB), h = this.s << c & this.DM, g; | |
for (g = this.t - 1; 0 <= g; --g) b[g + f + 1] = this[g] >> d | h, h = (this[g] & e) << c; | |
for (g = f - 1; 0 <= g; --g) b[g] = 0; | |
b[f] = h; | |
b.t = this.t + f + 1; | |
b.s = this.s; | |
b.clamp(); | |
} | |
function bnpRShiftTo(a, b) { | |
b.s = this.s; | |
var c = Math.floor(a / this.DB); | |
if (c >= this.t) b.t = 0; else { | |
var d = a % this.DB, e = this.DB - d, f = (1 << d) - 1; | |
b[0] = this[c] >> d; | |
for (var h = c + 1; h < this.t; ++h) b[h - c - 1] |= (this[h] & f) << e, b[h - c] = this[h] >> d; | |
0 < d && (b[this.t - c - 1] |= (this.s & f) << e); | |
b.t = this.t - c; | |
b.clamp(); | |
} | |
} | |
function bnpSubTo(a, b) { | |
for (var c = 0, d = 0, e = Math.min(a.t, this.t); c < e;) d += this[c] - a[c], b[c++] = d & this.DM, d >>= this.DB; | |
if (a.t < this.t) { | |
for (d -= a.s; c < this.t;) d += this[c], b[c++] = d & this.DM, d >>= this.DB; | |
d += this.s; | |
} else { | |
for (d += this.s; c < a.t;) d -= a[c], b[c++] = d & this.DM, d >>= this.DB; | |
d -= a.s; | |
} | |
b.s = 0 > d ? -1 : 0; | |
-1 > d ? b[c++] = this.DV + d : 0 < d && (b[c++] = d); | |
b.t = c; | |
b.clamp(); | |
} | |
function bnpMultiplyTo(a, b) { | |
var c = this.abs(), d = a.abs(), e = c.t; | |
for (b.t = e + d.t; 0 <= --e;) b[e] = 0; | |
for (e = 0; e < d.t; ++e) b[e + c.t] = c.am(0, d[e], b, e, 0, c.t); | |
b.s = 0; | |
b.clamp(); | |
this.s != a.s && BigInteger.ZERO.subTo(b, b); | |
} | |
function bnpSquareTo(a) { | |
for (var b = this.abs(), c = a.t = 2 * b.t; 0 <= --c;) a[c] = 0; | |
for (c = 0; c < b.t - 1; ++c) { | |
var d = b.am(c, b[c], a, 2 * c, 0, 1); | |
if ((a[c + b.t] += b.am(c + 1, 2 * b[c], a, 2 * c + 1, d, b.t - c - 1)) >= b.DV) a[c + b.t] -= b.DV, a[c + b.t + 1] = 1; | |
} | |
0 < a.t && (a[a.t - 1] += b.am(c, b[c], a, 2 * c, 0, 1)); | |
a.s = 0; | |
a.clamp(); | |
} | |
function bnpDivRemTo(a, b, c) { | |
var d = a.abs(); | |
if (!(0 >= d.t)) { | |
var e = this.abs(); | |
if (e.t < d.t) null != b && b.fromInt(0), null != c && this.copyTo(c); else { | |
null == c && (c = nbi()); | |
var f = nbi(), h = this.s; | |
a = a.s; | |
var g = this.DB - nbits(d[d.t - 1]); | |
0 < g ? (d.lShiftTo(g, f), e.lShiftTo(g, c)) : (d.copyTo(f), e.copyTo(c)); | |
d = f.t; | |
e = f[d - 1]; | |
if (0 != e) { | |
var l = e * (1 << this.F1) + (1 < d ? f[d - 2] >> this.F2 : 0), n = this.FV / l, l = (1 << this.F1) / l, p = 1 << this.F2, u = c.t, x = u - d, r = null == b ? nbi() : b; | |
f.dlShiftTo(x, r); | |
0 <= c.compareTo(r) && (c[c.t++] = 1, c.subTo(r, c)); | |
BigInteger.ONE.dlShiftTo(d, r); | |
for (r.subTo(f, f); f.t < d;) f[f.t++] = 0; | |
for (; 0 <= --x;) { | |
var v = c[--u] == e ? this.DM : Math.floor(c[u] * n + (c[u - 1] + p) * l); | |
if ((c[u] += f.am(0, v, c, x, 0, d)) < v) { | |
f.dlShiftTo(x, r); | |
for (c.subTo(r, c); c[u] < --v;) c.subTo(r, c); | |
} | |
} | |
null != b && (c.drShiftTo(d, b), h != a && BigInteger.ZERO.subTo(b, b)); | |
c.t = d; | |
c.clamp(); | |
0 < g && c.rShiftTo(g, c); | |
0 > h && BigInteger.ZERO.subTo(c, c); | |
} | |
} | |
} | |
} | |
function bnMod(a) { | |
var b = nbi(); | |
this.abs().divRemTo(a, null, b); | |
0 > this.s && 0 < b.compareTo(BigInteger.ZERO) && a.subTo(b, b); | |
return b; | |
} | |
function Classic(a) { | |
this.m = a; | |
} | |
function cConvert(a) { | |
return 0 > a.s || 0 <= a.compareTo(this.m) ? a.mod(this.m) : a; | |
} | |
function cReduce(a) { | |
a.divRemTo(this.m, null, a); | |
} | |
function cMulTo(a, b, c) { | |
a.multiplyTo(b, c); | |
this.reduce(c); | |
} | |
function cSqrTo(a, b) { | |
a.squareTo(b); | |
this.reduce(b); | |
} | |
Classic.prototype.convert = cConvert; | |
Classic.prototype.revert = cRevert; | |
Classic.prototype.reduce = cReduce; | |
Classic.prototype.mulTo = cMulTo; | |
Classic.prototype.sqrTo = cSqrTo; | |
function bnpInvDigit() { | |
if (1 > this.t) return 0; | |
var a = this[0]; | |
if (0 == (a & 1)) return 0; | |
var b = a & 3, b = b * (2 - (a & 15) * b) & 15, b = b * (2 - (a & 255) * b) & 255, b = b * (2 - ((a & 65535) * b & 65535)) & 65535, b = b * (2 - a * b % this.DV) % this.DV; | |
return 0 < b ? this.DV - b : -b; | |
} | |
function Montgomery(a) { | |
this.m = a; | |
this.mp = a.invDigit(); | |
this.mpl = this.mp & 32767; | |
this.mph = this.mp >> 15; | |
this.um = (1 << a.DB - 15) - 1; | |
this.mt2 = 2 * a.t; | |
} | |
function montConvert(a) { | |
var b = nbi(); | |
a.abs().dlShiftTo(this.m.t, b); | |
b.divRemTo(this.m, null, b); | |
0 > a.s && 0 < b.compareTo(BigInteger.ZERO) && this.m.subTo(b, b); | |
return b; | |
} | |
function montRevert(a) { | |
var b = nbi(); | |
a.copyTo(b); | |
this.reduce(b); | |
return b; | |
} | |
function montReduce(a) { | |
for (; a.t <= this.mt2;) a[a.t++] = 0; | |
for (var b = 0; b < this.m.t; ++b) { | |
var c = a[b] & 32767, d = c * this.mpl + ((c * this.mph + (a[b] >> 15) * this.mpl & this.um) << 15) & a.DM, c = b + this.m.t; | |
for (a[c] += this.m.am(0, d, a, b, 0, this.m.t); a[c] >= a.DV;) a[c] -= a.DV, a[++c]++; | |
} | |
a.clamp(); | |
a.drShiftTo(this.m.t, a); | |
0 <= a.compareTo(this.m) && a.subTo(this.m, a); | |
} | |
function montSqrTo(a, b) { | |
a.squareTo(b); | |
this.reduce(b); | |
} | |
function montMulTo(a, b, c) { | |
a.multiplyTo(b, c); | |
this.reduce(c); | |
} | |
Montgomery.prototype.convert = montConvert; | |
Montgomery.prototype.revert = montRevert; | |
Montgomery.prototype.reduce = montReduce; | |
Montgomery.prototype.mulTo = montMulTo; | |
Montgomery.prototype.sqrTo = montSqrTo; | |
function bnpExp(a, b) { | |
if (4294967295 < a || 1 > a) return BigInteger.ONE; | |
var c = nbi(), d = nbi(), e = b.convert(this), f = nbits(a) - 1; | |
for (e.copyTo(c); 0 <= --f;) if (b.sqrTo(c, d), 0 < (a & 1 << f)) b.mulTo(d, e, c); else var h = c, c = d, d = h; | |
return b.revert(c); | |
} | |
function bnModPowInt(a, b) { | |
var c; | |
c = 256 > a || b.isEven() ? new Classic(b) : new Montgomery(b); | |
return this.exp(a, c); | |
} | |
BigInteger.prototype.copyTo = bnpCopyTo; | |
BigInteger.prototype.fromInt = bnpFromInt; | |
BigInteger.prototype.fromString = bnpFromString; | |
BigInteger.prototype.clamp = bnpClamp; | |
BigInteger.prototype.dlShiftTo = bnpDLShiftTo; | |
BigInteger.prototype.drShiftTo = bnpDRShiftTo; | |
BigInteger.prototype.lShiftTo = bnpLShiftTo; | |
BigInteger.prototype.rShiftTo = bnpRShiftTo; | |
BigInteger.prototype.subTo = bnpSubTo; | |
BigInteger.prototype.multiplyTo = bnpMultiplyTo; | |
BigInteger.prototype.squareTo = bnpSquareTo; | |
BigInteger.prototype.divRemTo = bnpDivRemTo; | |
BigInteger.prototype.invDigit = bnpInvDigit; | |
BigInteger.prototype.isEven = bnpIsEven; | |
BigInteger.prototype.exp = bnpExp; | |
BigInteger.prototype.toString = bnToString; | |
BigInteger.prototype.negate = bnNegate; | |
BigInteger.prototype.abs = bnAbs; | |
BigInteger.prototype.compareTo = bnCompareTo; | |
BigInteger.prototype.bitLength = bnBitLength; | |
BigInteger.prototype.mod = bnMod; | |
BigInteger.prototype.modPowInt = bnModPowInt; | |
BigInteger.ZERO = nbv(0); | |
BigInteger.ONE = nbv(1); | |
function bnClone() { | |
var a = nbi(); | |
this.copyTo(a); | |
return a; | |
} | |
function bnIntValue() { | |
if (0 > this.s) { | |
if (1 == this.t) return this[0] - this.DV; | |
if (0 == this.t) return -1; | |
} else { | |
if (1 == this.t) return this[0]; | |
if (0 == this.t) return 0; | |
} | |
return (this[1] & (1 << 32 - this.DB) - 1) << this.DB | this[0]; | |
} | |
function bnByteValue() { | |
return 0 == this.t ? this.s : this[0] << 24 >> 24; | |
} | |
function bnShortValue() { | |
return 0 == this.t ? this.s : this[0] << 16 >> 16; | |
} | |
function bnSigNum() { | |
return 0 > this.s ? -1 : 0 >= this.t || 1 == this.t && 0 >= this[0] ? 0 : 1; | |
} | |
function bnpToRadix(a) { | |
null == a && (a = 10); | |
if (0 == this.signum() || 2 > a || 36 < a) return "0"; | |
var b = this.chunkSize(a), b = Math.pow(a, b), c = nbv(b), d = nbi(), e = nbi(), f = ""; | |
for (this.divRemTo(c, d, e); 0 < d.signum();) f = (b + e.intValue()).toString(a).substr(1) + f, d.divRemTo(c, d, e); | |
return e.intValue().toString(a) + f; | |
} | |
function bnpFromRadix(a, b) { | |
this.fromInt(0); | |
null == b && (b = 10); | |
for (var c = this.chunkSize(b), d = Math.pow(b, c), e = false, f = 0, h = 0, g = 0; g < a.length; ++g) { | |
var l = intAt(a, g); | |
0 > l ? "-" == a.charAt(g) && 0 == this.signum() && (e = true) : (h = b * h + l, ++f >= c && (this.dMultiply(d), this.dAddOffset(h, 0), h = f = 0)); | |
} | |
0 < f && (this.dMultiply(Math.pow(b, f)), this.dAddOffset(h, 0)); | |
e && BigInteger.ZERO.subTo(this, this); | |
} | |
function bnpFromNumber(a, b, c) { | |
if ("number" == typeof b) if (2 > a) this.fromInt(1); else { | |
this.fromNumber(a, c); | |
this.testBit(a - 1) || this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this); | |
for (this.isEven() && this.dAddOffset(1, 0); !this.isProbablePrime(b);) this.dAddOffset(2, 0), this.bitLength() > a && this.subTo(BigInteger.ONE.shiftLeft(a - 1), this); | |
} else { | |
c = []; | |
var d = a & 7; | |
c.length = (a >> 3) + 1; | |
b.nextBytes(c); | |
c[0] = 0 < d ? c[0] & (1 << d) - 1 : 0; | |
this.fromString(c, 256); | |
} | |
} | |
function bnToByteArray() { | |
var a = this.t, b = []; | |
b[0] = this.s; | |
var c = this.DB - a * this.DB % 8, d, e = 0; | |
if (0 < a--) { | |
if (c < this.DB && (d = this[a] >> c) != (this.s & this.DM) >> c) b[e++] = d | this.s << this.DB - c; | |
for (; 0 <= a;) if (8 > c ? (d = (this[a] & (1 << c) - 1) << 8 - c, d |= this[--a] >> (c += this.DB - 8)) : (d = this[a] >> (c -= 8) & 255, 0 >= c && (c += this.DB, --a)), 0 != (d & 128) && (d |= -256), 0 == e && (this.s & 128) != (d & 128) && ++e, 0 < e || d != this.s) b[e++] = d; | |
} | |
return b; | |
} | |
function bnMin(a) { | |
return 0 > this.compareTo(a) ? this : a; | |
} | |
function bnMax(a) { | |
return 0 < this.compareTo(a) ? this : a; | |
} | |
function bnpBitwiseTo(a, b, c) { | |
var d, e, f = Math.min(a.t, this.t); | |
for (d = 0; d < f; ++d) c[d] = b(this[d], a[d]); | |
if (a.t < this.t) { | |
e = a.s & this.DM; | |
for (d = f; d < this.t; ++d) c[d] = b(this[d], e); | |
c.t = this.t; | |
} else { | |
e = this.s & this.DM; | |
for (d = f; d < a.t; ++d) c[d] = b(e, a[d]); | |
c.t = a.t; | |
} | |
c.s = b(this.s, a.s); | |
c.clamp(); | |
} | |
function bnAnd(a) { | |
var b = nbi(); | |
this.bitwiseTo(a, op_and, b); | |
return b; | |
} | |
function bnOr(a) { | |
var b = nbi(); | |
this.bitwiseTo(a, op_or, b); | |
return b; | |
} | |
function bnXor(a) { | |
var b = nbi(); | |
this.bitwiseTo(a, op_xor, b); | |
return b; | |
} | |
function bnAndNot(a) { | |
var b = nbi(); | |
this.bitwiseTo(a, op_andnot, b); | |
return b; | |
} | |
function bnNot() { | |
for (var a = nbi(), b = 0; b < this.t; ++b) a[b] = this.DM & ~this[b]; | |
a.t = this.t; | |
a.s = ~this.s; | |
return a; | |
} | |
function bnShiftLeft(a) { | |
var b = nbi(); | |
0 > a ? this.rShiftTo(-a, b) : this.lShiftTo(a, b); | |
return b; | |
} | |
function bnShiftRight(a) { | |
var b = nbi(); | |
0 > a ? this.lShiftTo(-a, b) : this.rShiftTo(a, b); | |
return b; | |
} | |
function lbit(a) { | |
if (0 == a) return -1; | |
var b = 0; | |
0 == (a & 65535) && (a >>= 16, b += 16); | |
0 == (a & 255) && (a >>= 8, b += 8); | |
0 == (a & 15) && (a >>= 4, b += 4); | |
0 == (a & 3) && (a >>= 2, b += 2); | |
0 == (a & 1) && ++b; | |
return b; | |
} | |
function bnGetLowestSetBit() { | |
for (var a = 0; a < this.t; ++a) if (0 != this[a]) return a * this.DB + lbit(this[a]); | |
return 0 > this.s ? this.t * this.DB : -1; | |
} | |
function cbit(a) { | |
for (var b = 0; 0 != a;) a &= a - 1, ++b; | |
return b; | |
} | |
function bnBitCount() { | |
for (var a = 0, b = this.s & this.DM, c = 0; c < this.t; ++c) a += cbit(this[c] ^ b); | |
return a; | |
} | |
function bnTestBit(a) { | |
var b = Math.floor(a / this.DB); | |
return b >= this.t ? 0 != this.s : 0 != (this[b] & 1 << a % this.DB); | |
} | |
function bnpChangeBit(a, b) { | |
var c = BigInteger.ONE.shiftLeft(a); | |
this.bitwiseTo(c, b, c); | |
return c; | |
} | |
function bnpAddTo(a, b) { | |
for (var c = 0, d = 0, e = Math.min(a.t, this.t); c < e;) d += this[c] + a[c], b[c++] = d & this.DM, d >>= this.DB; | |
if (a.t < this.t) { | |
for (d += a.s; c < this.t;) d += this[c], b[c++] = d & this.DM, d >>= this.DB; | |
d += this.s; | |
} else { | |
for (d += this.s; c < a.t;) d += a[c], b[c++] = d & this.DM, d >>= this.DB; | |
d += a.s; | |
} | |
b.s = 0 > d ? -1 : 0; | |
0 < d ? b[c++] = d : -1 > d && (b[c++] = this.DV + d); | |
b.t = c; | |
b.clamp(); | |
} | |
function bnAdd(a) { | |
var b = nbi(); | |
this.addTo(a, b); | |
return b; | |
} | |
function bnSubtract(a) { | |
var b = nbi(); | |
this.subTo(a, b); | |
return b; | |
} | |
function bnMultiply(a) { | |
var b = nbi(); | |
this.multiplyTo(a, b); | |
return b; | |
} | |
function bnSquare() { | |
var a = nbi(); | |
this.squareTo(a); | |
return a; | |
} | |
function bnDivide(a) { | |
var b = nbi(); | |
this.divRemTo(a, b, null); | |
return b; | |
} | |
function bnRemainder(a) { | |
var b = nbi(); | |
this.divRemTo(a, null, b); | |
return b; | |
} | |
function bnDivideAndRemainder(a) { | |
var b = nbi(), c = nbi(); | |
this.divRemTo(a, b, c); | |
return [b, c]; | |
} | |
function bnpDMultiply(a) { | |
this[this.t] = this.am(0, a - 1, this, 0, 0, this.t); | |
++this.t; | |
this.clamp(); | |
} | |
function bnpDAddOffset(a, b) { | |
if (0 != a) { | |
for (; this.t <= b;) this[this.t++] = 0; | |
for (this[b] += a; this[b] >= this.DV;) this[b] -= this.DV, ++b >= this.t && (this[this.t++] = 0), ++this[b]; | |
} | |
} | |
function NullExp() {} | |
function nMulTo(a, b, c) { | |
a.multiplyTo(b, c); | |
} | |
function nSqrTo(a, b) { | |
a.squareTo(b); | |
} | |
NullExp.prototype.convert = nNop; | |
NullExp.prototype.revert = nNop; | |
NullExp.prototype.mulTo = nMulTo; | |
NullExp.prototype.sqrTo = nSqrTo; | |
function bnpMultiplyLowerTo(a, b, c) { | |
var d = Math.min(this.t + a.t, b); | |
c.s = 0; | |
for (c.t = d; 0 < d;) c[--d] = 0; | |
var e; | |
for (e = c.t - this.t; d < e; ++d) c[d + this.t] = this.am(0, a[d], c, d, 0, this.t); | |
for (e = Math.min(a.t, b); d < e; ++d) this.am(0, a[d], c, d, 0, b - d); | |
c.clamp(); | |
} | |
function bnpMultiplyUpperTo(a, b, c) { | |
--b; | |
var d = c.t = this.t + a.t - b; | |
for (c.s = 0; 0 <= --d;) c[d] = 0; | |
for (d = Math.max(b - this.t, 0); d < a.t; ++d) c[this.t + d - b] = this.am(b - d, a[d], c, 0, 0, this.t + d - b); | |
c.clamp(); | |
c.drShiftTo(1, c); | |
} | |
function Barrett(a) { | |
this.r2 = nbi(); | |
this.q3 = nbi(); | |
BigInteger.ONE.dlShiftTo(2 * a.t, this.r2); | |
this.mu = this.r2.divide(a); | |
this.m = a; | |
} | |
function barrettConvert(a) { | |
if (0 > a.s || a.t > 2 * this.m.t) return a.mod(this.m); | |
if (0 > a.compareTo(this.m)) return a; | |
var b = nbi(); | |
a.copyTo(b); | |
this.reduce(b); | |
return b; | |
} | |
function barrettReduce(a) { | |
a.drShiftTo(this.m.t - 1, this.r2); | |
a.t > this.m.t + 1 && (a.t = this.m.t + 1, a.clamp()); | |
this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3); | |
for (this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2); 0 > a.compareTo(this.r2);) a.dAddOffset(1, this.m.t + 1); | |
for (a.subTo(this.r2, a); 0 <= a.compareTo(this.m);) a.subTo(this.m, a); | |
} | |
function barrettSqrTo(a, b) { | |
a.squareTo(b); | |
this.reduce(b); | |
} | |
function barrettMulTo(a, b, c) { | |
a.multiplyTo(b, c); | |
this.reduce(c); | |
} | |
Barrett.prototype.convert = barrettConvert; | |
Barrett.prototype.revert = barrettRevert; | |
Barrett.prototype.reduce = barrettReduce; | |
Barrett.prototype.mulTo = barrettMulTo; | |
Barrett.prototype.sqrTo = barrettSqrTo; | |
function bnModPow(a, b) { | |
var c = a.bitLength(), d, e = nbv(1), f; | |
if (0 >= c) return e; | |
d = 18 > c ? 1 : 48 > c ? 3 : 144 > c ? 4 : 768 > c ? 5 : 6; | |
f = 8 > c ? new Classic(b) : b.isEven() ? new Barrett(b) : new Montgomery(b); | |
var h = [], g = 3, l = d - 1, n = (1 << d) - 1; | |
h[1] = f.convert(this); | |
if (1 < d) { | |
c = nbi(); | |
for (f.sqrTo(h[1], c); g <= n;) h[g] = nbi(), f.mulTo(c, h[g - 2], h[g]), g += 2; | |
} | |
for (var p = a.t - 1, u, x = true, r = nbi(), c = nbits(a[p]) - 1; 0 <= p;) { | |
c >= l ? u = a[p] >> c - l & n : (u = (a[p] & (1 << c + 1) - 1) << l - c, 0 < p && (u |= a[p - 1] >> this.DB + c - l)); | |
for (g = d; 0 == (u & 1);) u >>= 1, --g; | |
if (0 > (c -= g)) c += this.DB, --p; | |
if (x) h[u].copyTo(e), x = false; else { | |
for (; 1 < g;) f.sqrTo(e, r), f.sqrTo(r, e), g -= 2; | |
0 < g ? f.sqrTo(e, r) : (g = e, e = r, r = g); | |
f.mulTo(r, h[u], e); | |
} | |
for (; 0 <= p && 0 == (a[p] & 1 << c);) f.sqrTo(e, r), g = e, e = r, r = g, 0 > --c && (c = this.DB - 1, --p); | |
} | |
return f.revert(e); | |
} | |
(function () { | |
var a = [], b = window.postMessage && window.addEventListener; | |
b && window.addEventListener("message", function (b) { | |
b.source == window && "zero-timeout-message" == b.data && (b.stopPropagation(), 0 < a.length && a.shift()()); | |
}, true); | |
window.setZeroTimeout = function (c) { | |
b ? (a.push(c), window.postMessage("zero-timeout-message", "*")) : window.setTimeout(c, 1); | |
}; | |
}()); | |
function bnModPowPromise(a, b) { | |
function c() { | |
if (0 <= r) { | |
e >= p ? v = a[r] >> e - p & u : (v = (a[r] & (1 << e + 1) - 1) << p - e, 0 < r && (v |= a[r - 1] >> this.DB + e - p)); | |
for (n = f; 0 == (v & 1);) v >>= 1, --n; | |
if (0 > (e -= n)) e += this.DB, --r; | |
if (J) l[v].copyTo(h), J = false; else { | |
for (; 1 < n;) g.sqrTo(h, s), g.sqrTo(s, h), n -= 2; | |
0 < n ? g.sqrTo(h, s) : (y = h, h = s, s = y); | |
g.mulTo(s, l[v], h); | |
} | |
for (; 0 <= r && 0 == (a[r] & 1 << e);) g.sqrTo(h, s), y = h, h = s, s = y, 0 > --e && (e = this.DB - 1, --r); | |
window.setZeroTimeout(d); | |
} else K.resolve(g.revert(h)); | |
} | |
function d() { | |
c.call(N); | |
} | |
var e = a.bitLength(), f, h = nbv(1), g; | |
if (0 >= e) return h; | |
f = 18 > e ? 1 : 48 > e ? 3 : 144 > e ? 4 : 768 > e ? 5 : 6; | |
g = 8 > e ? new Classic(b) : b.isEven() ? new Barrett(b) : new Montgomery(b); | |
var l = [], n = 3, p = f - 1, u = (1 << f) - 1; | |
l[1] = g.convert(this); | |
if (1 < f) { | |
var x = nbi(); | |
for (g.sqrTo(l[1], x); n <= u;) l[n] = nbi(), g.mulTo(x, l[n - 2], l[n]), n += 2; | |
} | |
var r = a.t - 1, v, J = true, s = nbi(), y, e = nbits(a[r]) - 1, K = $.Deferred(), N = this; | |
window.setZeroTimeout(d); | |
return K.promise(); | |
} | |
function bnGCD(a) { | |
var b = 0 > this.s ? this.negate() : this.clone(); | |
a = 0 > a.s ? a.negate() : a.clone(); | |
if (0 > b.compareTo(a)) { | |
var c = b, b = a; | |
a = c; | |
} | |
var c = b.getLowestSetBit(), d = a.getLowestSetBit(); | |
if (0 > d) return b; | |
c < d && (d = c); | |
0 < d && (b.rShiftTo(d, b), a.rShiftTo(d, a)); | |
for (; 0 < b.signum();) 0 < (c = b.getLowestSetBit()) && b.rShiftTo(c, b), 0 < (c = a.getLowestSetBit()) && a.rShiftTo(c, a), 0 <= b.compareTo(a) ? (b.subTo(a, b), b.rShiftTo(1, b)) : (a.subTo(b, a), a.rShiftTo(1, a)); | |
0 < d && a.lShiftTo(d, a); | |
return a; | |
} | |
function bnpModInt(a) { | |
if (0 >= a) return 0; | |
var b = this.DV % a, c = 0 > this.s ? a - 1 : 0; | |
if (0 < this.t) if (0 == b) c = this[0] % a; else for (var d = this.t - 1; 0 <= d; --d) c = (b * c + this[d]) % a; | |
return c; | |
} | |
function bnModInverse(a) { | |
var b = a.isEven(); | |
if (this.isEven() && b || 0 == a.signum()) return BigInteger.ZERO; | |
for (var c = a.clone(), d = this.clone(), e = nbv(1), f = nbv(0), h = nbv(0), g = nbv(1); 0 != c.signum();) { | |
for (; c.isEven();) { | |
c.rShiftTo(1, c); | |
if (b) { | |
if (!e.isEven() || !f.isEven()) e.addTo(this, e), f.subTo(a, f); | |
e.rShiftTo(1, e); | |
} else f.isEven() || f.subTo(a, f); | |
f.rShiftTo(1, f); | |
} | |
for (; d.isEven();) { | |
d.rShiftTo(1, d); | |
if (b) { | |
if (!h.isEven() || !g.isEven()) h.addTo(this, h), g.subTo(a, g); | |
h.rShiftTo(1, h); | |
} else g.isEven() || g.subTo(a, g); | |
g.rShiftTo(1, g); | |
} | |
0 <= c.compareTo(d) ? (c.subTo(d, c), b && e.subTo(h, e), f.subTo(g, f)) : (d.subTo(c, d), b && h.subTo(e, h), g.subTo(f, g)); | |
} | |
if (0 != d.compareTo(BigInteger.ONE)) return BigInteger.ZERO; | |
if (0 <= g.compareTo(a)) return g.subtract(a); | |
if (0 > g.signum()) g.addTo(a, g); else return g; | |
return 0 > g.signum() ? g.add(a) : g; | |
} | |
var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997], lplim = 67108864 / lowprimes[lowprimes.length - 1]; | |
function bnIsProbablePrime(a) { | |
var b, c = this.abs(); | |
if (1 == c.t && c[0] <= lowprimes[lowprimes.length - 1]) { | |
for (b = 0; b < lowprimes.length; ++b) if (c[0] == lowprimes[b]) return true; | |
return false; | |
} | |
if (c.isEven()) return false; | |
for (b = 1; b < lowprimes.length;) { | |
for (var d = lowprimes[b], e = b + 1; e < lowprimes.length && d < lplim;) d *= lowprimes[e++]; | |
for (d = c.modInt(d); b < e;) if (0 == d % lowprimes[b++]) return false; | |
} | |
return c.millerRabin(a); | |
} | |
function bnpMillerRabin(a) { | |
var b = this.subtract(BigInteger.ONE), c = b.getLowestSetBit(); | |
if (0 >= c) return false; | |
var d = b.shiftRight(c); | |
a = a + 1 >> 1; | |
a > lowprimes.length && (a = lowprimes.length); | |
for (var e = nbi(), f = 0; f < a; ++f) { | |
e.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]); | |
var h = e.modPow(d, this); | |
if (0 != h.compareTo(BigInteger.ONE) && 0 != h.compareTo(b)) { | |
for (var g = 1; g++ < c && 0 != h.compareTo(b);) if (h = h.modPowInt(2, this), 0 == h.compareTo(BigInteger.ONE)) return false; | |
if (0 != h.compareTo(b)) return false; | |
} | |
} | |
return true; | |
} | |
BigInteger.prototype.chunkSize = bnpChunkSize; | |
BigInteger.prototype.toRadix = bnpToRadix; | |
BigInteger.prototype.fromRadix = bnpFromRadix; | |
BigInteger.prototype.fromNumber = bnpFromNumber; | |
BigInteger.prototype.bitwiseTo = bnpBitwiseTo; | |
BigInteger.prototype.changeBit = bnpChangeBit; | |
BigInteger.prototype.addTo = bnpAddTo; | |
BigInteger.prototype.dMultiply = bnpDMultiply; | |
BigInteger.prototype.dAddOffset = bnpDAddOffset; | |
BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo; | |
BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo; | |
BigInteger.prototype.modInt = bnpModInt; | |
BigInteger.prototype.millerRabin = bnpMillerRabin; | |
BigInteger.prototype.clone = bnClone; | |
BigInteger.prototype.intValue = bnIntValue; | |
BigInteger.prototype.byteValue = bnByteValue; | |
BigInteger.prototype.shortValue = bnShortValue; | |
BigInteger.prototype.signum = bnSigNum; | |
BigInteger.prototype.toByteArray = bnToByteArray; | |
BigInteger.prototype.equals = bnEquals; | |
BigInteger.prototype.min = bnMin; | |
BigInteger.prototype.max = bnMax; | |
BigInteger.prototype.and = bnAnd; | |
BigInteger.prototype.or = bnOr; | |
BigInteger.prototype.xor = bnXor; | |
BigInteger.prototype.andNot = bnAndNot; | |
BigInteger.prototype.not = bnNot; | |
BigInteger.prototype.shiftLeft = bnShiftLeft; | |
BigInteger.prototype.shiftRight = bnShiftRight; | |
BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit; | |
BigInteger.prototype.bitCount = bnBitCount; | |
BigInteger.prototype.testBit = bnTestBit; | |
BigInteger.prototype.setBit = bnSetBit; | |
BigInteger.prototype.clearBit = bnClearBit; | |
BigInteger.prototype.flipBit = bnFlipBit; | |
BigInteger.prototype.add = bnAdd; | |
BigInteger.prototype.subtract = bnSubtract; | |
BigInteger.prototype.multiply = bnMultiply; | |
BigInteger.prototype.divide = bnDivide; | |
BigInteger.prototype.remainder = bnRemainder; | |
BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder; | |
BigInteger.prototype.modPow = bnModPow; | |
BigInteger.prototype.modPowPromise = bnModPowPromise; | |
BigInteger.prototype.modInverse = bnModInverse; | |
BigInteger.prototype.pow = bnPow; | |
BigInteger.prototype.gcd = bnGCD; | |
BigInteger.prototype.isProbablePrime = bnIsProbablePrime; | |
BigInteger.prototype.square = bnSquare; | |
function Arcfour() { | |
this.j = this.i = 0; | |
this.S = []; | |
} | |
function ARC4init(a) { | |
var b, c, d; | |
for (b = 0; 256 > b; ++b) this.S[b] = b; | |
for (b = c = 0; 256 > b; ++b) c = c + this.S[b] + a[b % a.length] & 255, d = this.S[b], this.S[b] = this.S[c], this.S[c] = d; | |
this.j = this.i = 0; | |
} | |
function ARC4next() { | |
var a; | |
this.i = this.i + 1 & 255; | |
this.j = this.j + this.S[this.i] & 255; | |
a = this.S[this.i]; | |
this.S[this.i] = this.S[this.j]; | |
this.S[this.j] = a; | |
return this.S[a + this.S[this.i] & 255]; | |
} | |
Arcfour.prototype.init = ARC4init; | |
Arcfour.prototype.next = ARC4next; | |
function prng_newstate() { | |
return new Arcfour; | |
} | |
var rng_psize = 256, rng_state, rng_pool, rng_pptr; | |
function rng_seed_int(a) { | |
rng_pool[rng_pptr++] ^= a & 255; | |
rng_pool[rng_pptr++] ^= a >> 8 & 255; | |
rng_pool[rng_pptr++] ^= a >> 16 & 255; | |
rng_pool[rng_pptr++] ^= a >> 24 & 255; | |
rng_pptr >= rng_psize && (rng_pptr -= rng_psize); | |
} | |
function rng_seed_time() { | |
rng_seed_int((new Date).getTime()); | |
} | |
if (null == rng_pool) { | |
rng_pool = []; | |
rng_pptr = 0; | |
var t; | |
if (window.crypto && window.crypto.getRandomValues) { | |
var ua = new Uint8Array(32); | |
window.crypto.getRandomValues(ua); | |
for (t = 0; 32 > t; ++t) rng_pool[rng_pptr++] = ua[t]; | |
} | |
if ("Netscape" == navigator.appName && "5" > navigator.appVersion && window.crypto) { | |
var z = window.crypto.random(32); | |
for (t = 0; t < z.length; ++t) rng_pool[rng_pptr++] = z.charCodeAt(t) & 255; | |
} | |
for (; rng_pptr < rng_psize;) t = Math.floor(65536 * Math.random()), rng_pool[rng_pptr++] = t >>> 8, rng_pool[rng_pptr++] = t & 255; | |
rng_pptr = 0; | |
rng_seed_time(); | |
} | |
function rng_get_byte() { | |
if (null == rng_state) { | |
rng_seed_time(); | |
rng_state = prng_newstate(); | |
rng_state.init(rng_pool); | |
for (rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr) rng_pool[rng_pptr] = 0; | |
rng_pptr = 0; | |
} | |
return rng_state.next(); | |
} | |
function rng_get_bytes(a) { | |
var b; | |
for (b = 0; b < a.length; ++b) a[b] = rng_get_byte(); | |
} | |
function SecureRandom() {} | |
SecureRandom.prototype.nextBytes = rng_get_bytes; | |
(function () { | |
function a(a) { | |
throw a; | |
} | |
function b(a, b) { | |
this.a = a; | |
this.b = b; | |
} | |
function c(a, b) { | |
var c = [], d = (1 << b) - 1, e = a.length * b, f; | |
for (f = 0; f < e; f += b) c[f >>> 5] |= (a.charCodeAt(f / b) & d) << 32 - b - f % 32; | |
return {value: c, binLen: e}; | |
} | |
function d(b) { | |
var c = [], d = b.length, e, f; | |
0 !== d % 2 && a("String of HEX type must be in byte increments"); | |
for (e = 0; e < d; e += 2) f = parseInt(b.substr(e, 2), 16), isNaN(f) && a("String of HEX type contains invalid characters"), c[e >>> 3] |= f << 24 - 4 * (e % 8); | |
return {value: c, binLen: 4 * d}; | |
} | |
function e(b) { | |
var c = [], d = 0, e, f, g, h, l; | |
-1 === b.search(/^[a-zA-Z0-9=+\/]+$/) && a("Invalid character in base-64 string"); | |
e = b.indexOf("="); | |
b = b.replace(/\=/g, ""); | |
-1 !== e && e < b.length && a("Invalid '=' found in base-64 string"); | |
for (f = 0; f < b.length; f += 4) { | |
l = b.substr(f, 4); | |
for (g = h = 0; g < l.length; g += 1) e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(l[g]), h |= e << 18 - 6 * g; | |
for (g = 0; g < l.length - 1; g += 1) c[d >> 2] |= (h >>> 16 - 8 * g & 255) << 24 - 8 * (d % 4), d += 1; | |
} | |
return {value: c, binLen: 8 * d}; | |
} | |
function f(a, b) { | |
var c = "", d = 4 * a.length, e, f; | |
for (e = 0; e < d; e += 1) f = a[e >>> 2] >>> 8 * (3 - e % 4), c += "0123456789abcdef".charAt(f >>> 4 & 15) + "0123456789abcdef".charAt(f & 15); | |
return b.outputUpper ? c.toUpperCase() : c; | |
} | |
function h(a, b) { | |
var c = "", d = 4 * a.length, e, f, g; | |
for (e = 0; e < d; e += 3) { | |
g = (a[e >>> 2] >>> 8 * (3 - e % 4) & 255) << 16 | (a[e + 1 >>> 2] >>> 8 * (3 - (e + 1) % 4) & 255) << 8 | a[e + 2 >>> 2] >>> 8 * (3 - (e + 2) % 4) & 255; | |
for (f = 0; 4 > f; f += 1) c = 8 * e + 6 * f <= 32 * a.length ? c + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(g >>> 6 * (3 - f) & 63) : c + b.b64Pad; | |
} | |
return c; | |
} | |
function g(b) { | |
var c = {outputUpper: false, b64Pad: "="}; | |
try { | |
b.hasOwnProperty("outputUpper") && (c.outputUpper = b.outputUpper), b.hasOwnProperty("b64Pad") && (c.b64Pad = b.b64Pad); | |
} catch (d) {} | |
"boolean" !== typeof c.outputUpper && a("Invalid outputUpper formatting option"); | |
"string" !== typeof c.b64Pad && a("Invalid b64Pad formatting option"); | |
return c; | |
} | |
function n(a, c) { | |
return 32 >= c ? new b(a.a >>> c | a.b << 32 - c & 4294967295, a.b >>> c | a.a << 32 - c & 4294967295) : new b(a.b >>> c - 32 | a.a << 64 - c & 4294967295, a.a >>> c - 32 | a.b << 64 - c & 4294967295); | |
} | |
function p(a, c) { | |
return 32 >= c ? new b(a.a >>> c, a.b >>> c | a.a << 32 - c & 4294967295) : new b(0, a.a >>> c - 32); | |
} | |
function x(a, c, d) { | |
return new b(a.a & c.a ^ ~a.a & d.a, a.b & c.b ^ ~a.b & d.b); | |
} | |
function v(a, c, d) { | |
return new b(a.a & c.a ^ a.a & d.a ^ c.a & d.a, a.b & c.b ^ a.b & d.b ^ c.b & d.b); | |
} | |
function s(a) { | |
var c = n(a, 28), d = n(a, 34); | |
a = n(a, 39); | |
return new b(c.a ^ d.a ^ a.a, c.b ^ d.b ^ a.b); | |
} | |
function K(a) { | |
var c = n(a, 14), d = n(a, 18); | |
a = n(a, 41); | |
return new b(c.a ^ d.a ^ a.a, c.b ^ d.b ^ a.b); | |
} | |
function M(a) { | |
var c = n(a, 1), d = n(a, 8); | |
a = p(a, 7); | |
return new b(c.a ^ d.a ^ a.a, c.b ^ d.b ^ a.b); | |
} | |
function R(a) { | |
var c = n(a, 19), d = n(a, 61); | |
a = p(a, 6); | |
return new b(c.a ^ d.a ^ a.a, c.b ^ d.b ^ a.b); | |
} | |
function G(a, b) { | |
var c = (a & 65535) + (b & 65535); | |
return ((a >>> 16) + (b >>> 16) + (c >>> 16) & 65535) << 16 | c & 65535; | |
} | |
function S(a, b, c, d) { | |
var e = (a & 65535) + (b & 65535) + (c & 65535) + (d & 65535); | |
return ((a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + (e >>> 16) & 65535) << 16 | e & 65535; | |
} | |
function H(a, b, c, d, e) { | |
var f = (a & 65535) + (b & 65535) + (c & 65535) + (d & 65535) + (e & 65535); | |
return ((a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + (e >>> 16) + (f >>> 16) & 65535) << 16 | f & 65535; | |
} | |
function F(a, c) { | |
var d, e, f; | |
d = (a.b & 65535) + (c.b & 65535); | |
e = (a.b >>> 16) + (c.b >>> 16) + (d >>> 16); | |
f = (e & 65535) << 16 | d & 65535; | |
d = (a.a & 65535) + (c.a & 65535) + (e >>> 16); | |
e = (a.a >>> 16) + (c.a >>> 16) + (d >>> 16); | |
return new b((e & 65535) << 16 | d & 65535, f); | |
} | |
function w(a, c, d, e) { | |
var f, g, h; | |
f = (a.b & 65535) + (c.b & 65535) + (d.b & 65535) + (e.b & 65535); | |
g = (a.b >>> 16) + (c.b >>> 16) + (d.b >>> 16) + (e.b >>> 16) + (f >>> 16); | |
h = (g & 65535) << 16 | f & 65535; | |
f = (a.a & 65535) + (c.a & 65535) + (d.a & 65535) + (e.a & 65535) + (g >>> 16); | |
g = (a.a >>> 16) + (c.a >>> 16) + (d.a >>> 16) + (e.a >>> 16) + (f >>> 16); | |
return new b((g & 65535) << 16 | f & 65535, h); | |
} | |
function q(a, c, d, e, f) { | |
var g, h, l; | |
g = (a.b & 65535) + (c.b & 65535) + (d.b & 65535) + (e.b & 65535) + (f.b & 65535); | |
h = (a.b >>> 16) + (c.b >>> 16) + (d.b >>> 16) + (e.b >>> 16) + (f.b >>> 16) + (g >>> 16); | |
l = (h & 65535) << 16 | g & 65535; | |
g = (a.a & 65535) + (c.a & 65535) + (d.a & 65535) + (e.a & 65535) + (f.a & 65535) + (h >>> 16); | |
h = (a.a >>> 16) + (c.a >>> 16) + (d.a >>> 16) + (e.a >>> 16) + (f.a >>> 16) + (g >>> 16); | |
return new b((h & 65535) << 16 | g & 65535, l); | |
} | |
function A(a, b) { | |
var c = [], d, e, f, g, h, l, n, q, w, A = [1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1518500249, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 1859775393, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 2400959708, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782, 3395469782]; | |
a[b >>> 5] |= 128 << 24 - b % 32; | |
a[(b + 65 >>> 9 << 4) + 15] = b; | |
w = a.length; | |
for (n = 0; n < w; n += 16) { | |
d = 1732584193; | |
e = 4023233417; | |
f = 2562383102; | |
g = 271733878; | |
h = 3285377520; | |
for (q = 0; 80 > q; q += 1) c[q] = 16 > q ? a[q + n] : (c[q - 3] ^ c[q - 8] ^ c[q - 14] ^ c[q - 16]) << 1 | (c[q - 3] ^ c[q - 8] ^ c[q - 14] ^ c[q - 16]) >>> 31, l = 20 > q ? H(d << 5 | d >>> 27, e & f ^ ~e & g, h, A[q], c[q]) : 40 > q ? H(d << 5 | d >>> 27, e ^ f ^ g, h, A[q], c[q]) : 60 > q ? H(d << 5 | d >>> 27, e & f ^ e & g ^ f & g, h, A[q], c[q]) : H(d << 5 | d >>> 27, e ^ f ^ g, h, A[q], c[q]), h = g, g = f, f = e << 30 | e >>> 2, e = d, d = l; | |
m[0] = G(d, 1732584193); | |
m[1] = G(e, 4023233417); | |
m[2] = G(f, 2562383102); | |
m[3] = G(g, 271733878); | |
m[4] = G(h, 3285377520); | |
} | |
return m; | |
} | |
function I(c, d, e) { | |
var f, g, h, l, n, A, p, I, ea, m, U, O, B, V, T, C, W, X, Y, Z, aa, D, ba, ca, k, da, P = [], fa, Q; | |
"SHA-224" === e || "SHA-256" === e ? (U = 64, f = (d + 65 >>> 9 << 4) + 15, V = 16, T = 1, k = Number, C = G, W = S, X = H, Y = N, Z = E, aa = J, D = y, ca = r, ba = u, da = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298], m = "SHA-224" === e ? [3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428] : [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]) : "SHA-384" === e || "SHA-512" === e ? (U = 80, f = (d + 128 >>> 10 << 5) + 31, V = 32, T = 2, k = b, C = F, W = w, X = q, Y = M, Z = R, aa = s, D = K, ca = v, ba = x, da = [new k(1116352408, 3609767458), new k(1899447441, 602891725), new k(3049323471, 3964484399), new k(3921009573, 2173295548), new k(961987163, 4081628472), new k(1508970993, 3053834265), new k(2453635748, 2937671579), new k(2870763221, 3664609560), new k(3624381080, 2734883394), new k(310598401, 1164996542), new k(607225278, 1323610764), new k(1426881987, 3590304994), new k(1925078388, 4068182383), new k(2162078206, 991336113), new k(2614888103, 633803317), new k(3248222580, 3479774868), new k(3835390401, 2666613458), new k(4022224774, 944711139), new k(264347078, 2341262773), new k(604807628, 2007800933), new k(770255983, 1495990901), new k(1249150122, 1856431235), new k(1555081692, 3175218132), new k(1996064986, 2198950837), new k(2554220882, 3999719339), new k(2821834349, 766784016), new k(2952996808, 2566594879), new k(3210313671, 3203337956), new k(3336571891, 1034457026), new k(3584528711, 2466948901), new k(113926993, 3758326383), new k(338241895, 168717936), new k(666307205, 1188179964), new k(773529912, 1546045734), new k(1294757372, 1522805485), new k(1396182291, 2643833823), new k(1695183700, 2343527390), new k(1986661051, 1014477480), new k(2177026350, 1206759142), new k(2456956037, 344077627), new k(2730485921, 1290863460), new k(2820302411, 3158454273), new k(3259730800, 3505952657), new k(3345764771, 106217008), new k(3516065817, 3606008344), new k(3600352804, 1432725776), new k(4094571909, 1467031594), new k(275423344, 851169720), new k(430227734, 3100823752), new k(506948616, 1363258195), new k(659060556, 3750685593), new k(883997877, 3785050280), new k(958139571, 3318307427), new k(1322822218, 3812723403), new k(1537002063, 2003034995), new k(1747873779, 3602036899), new k(1955562222, 1575990012), new k(2024104815, 1125592928), new k(2227730452, 2716904306), new k(2361852424, 442776044), new k(2428436474, 593698344), new k(2756734187, 3733110249), new k(3204031479, 2999351573), new k(3329325298, 3815920427), new k(3391569614, 3928383900), new k(3515267271, 566280711), new k(3940187606, 3454069534), new k(4118630271, 4000239992), new k(116418474, 1914138554), new k(174292421, 2731055270), new k(289380356, 3203993006), new k(460393269, 320620315), new k(685471733, 587496836), new k(852142971, 1086792851), new k(1017036298, 365543100), new k(1126000580, 2618297676), new k(1288033470, 3409855158), new k(1501505948, 4234509866), new k(1607167915, 987167468), new k(1816402316, 1246189591)], m = "SHA-384" === e ? [new k(3418070365, 3238371032), new k(1654270250, 914150663), new k(2438529370, 812702999), new k(355462360, 4144912697), new k(1731405415, 4290775857), new k(41048885895, 1750603025), new k(3675008525, 1694076839), new k(1203062813, 3204075428)] : [new k(1779033703, 4089235720), new k(3144134277, 2227873595), new k(1013904242, 4271175723), new k(2773480762, 1595750129), new k(1359893119, 2917565137), new k(2600822924, 725511199), new k(528734635, 4215389547), new k(1541459225, 327033209)]) : a("Unexpected error in SHA-2 implementation"); | |
c[d >>> 5] |= 128 << 24 - d % 32; | |
c[f] = d; | |
fa = c.length; | |
for (O = 0; O < fa; O += V) { | |
d = m[0]; | |
f = m[1]; | |
g = m[2]; | |
h = m[3]; | |
l = m[4]; | |
n = m[5]; | |
A = m[6]; | |
p = m[7]; | |
for (B = 0; B < U; B += 1) P[B] = 16 > B ? new k(c[B * T + O], c[B * T + O + 1]) : W(Z(P[B - 2]), P[B - 7], Y(P[B - 15]), P[B - 16]), I = X(p, D(l), ba(l, n, A), da[B], P[B]), ea = C(aa(d), ca(d, f, g)), p = A, A = n, n = l, l = C(h, I), h = g, g = f, f = d, d = C(I, ea); | |
m[0] = C(d, m[0]); | |
m[1] = C(f, m[1]); | |
m[2] = C(g, m[2]); | |
m[3] = C(h, m[3]); | |
m[4] = C(l, m[4]); | |
m[5] = C(n, m[5]); | |
m[6] = C(A, m[6]); | |
m[7] = C(p, m[7]); | |
} | |
"SHA-224" === e ? Q = [m[0], m[1], m[2], m[3], m[4], m[5], m[6]] : "SHA-256" === e ? Q = m : "SHA-384" === e ? Q = [m[0].a, m[0].b, m[1].a, m[1].b, m[2].a, m[2].b, m[3].a, m[3].b, m[4].a, m[4].b, m[5].a, m[5].b] : "SHA-512" === e ? Q = [m[0].a, m[0].b, m[1].a, m[1].b, m[2].a, m[2].b, m[3].a, m[3].b, m[4].a, m[4].b, m[5].a, m[5].b, m[6].a, m[6].b, m[7].a, m[7].b] : a("Unexpected error in SHA-2 implementation"); | |
return Q; | |
} | |
window.jsSHA = function (b, l, q) { | |
var n = null, H = null, r = null, w = null, p = null, F = 0, u = [0], v = 0, s = null, v = "undefined" !== typeof q ? q : 8; | |
8 === v || 16 === v || a("charSize must be 8 or 16"); | |
"HEX" === l ? (0 !== b.length % 2 && a("srcString of HEX type must be in byte increments"), s = d(b), F = s.binLen, u = s.value) : "ASCII" === l || "TEXT" === l ? (s = c(b, v), F = s.binLen, u = s.value) : "B64" === l ? (s = e(b), F = s.binLen, u = s.value) : a("inputFormat must be HEX, TEXT, ASCII, or B64"); | |
this.getHash = function (b, c, d) { | |
var e = null, l = u.slice(), q = ""; | |
switch (c) { | |
case "HEX": | |
e = f; | |
break; | |
case "B64": | |
e = h; | |
break; | |
default: | |
a("format must be HEX or B64"); | |
} | |
"SHA-1" === b ? (null === n && (n = A(l, F)), q = e(n, g(d))) : "SHA-224" === b ? (null === H && (H = I(l, F, b)), q = e(H, g(d))) : "SHA-256" === b ? (null === r && (r = I(l, F, b)), q = e(r, g(d))) : "SHA-384" === b ? (null === w && (w = I(l, F, b)), q = e(w, g(d))) : "SHA-512" === b ? (null === p && (p = I(l, F, b)), q = e(p, g(d))) : a("Chosen SHA variant is not supported"); | |
return q; | |
}; | |
this.getHMAC = function (b, l, q, n, H) { | |
var r, w, p, s, L, x = [], y = [], D = null; | |
switch (n) { | |
case "HEX": | |
r = f; | |
break; | |
case "B64": | |
r = h; | |
break; | |
default: | |
a("outputFormat must be HEX or B64"); | |
} | |
"SHA-1" === q ? (p = 64, L = 160) : "SHA-224" === q ? (p = 64, L = 224) : "SHA-256" === q ? (p = 64, L = 256) : "SHA-384" === q ? (p = 128, L = 384) : "SHA-512" === q ? (p = 128, L = 512) : a("Chosen SHA variant is not supported"); | |
"HEX" === l ? (D = d(b), s = D.binLen, w = D.value) : "ASCII" === l || "TEXT" === l ? (D = c(b, v), s = D.binLen, w = D.value) : "B64" === l ? (D = e(b), s = D.binLen, w = D.value) : a("inputFormat must be HEX, TEXT, ASCII, or B64"); | |
b = 8 * p; | |
l = p / 4 - 1; | |
p < s / 8 ? (w = "SHA-1" === q ? A(w, s) : I(w, s, q), w[l] &= 4294967040) : p > s / 8 && (w[l] &= 4294967040); | |
for (p = 0; p <= l; p += 1) x[p] = w[p] ^ 909522486, y[p] = w[p] ^ 1549556828; | |
q = "SHA-1" === q ? A(y.concat(A(x.concat(u), b + F)), b + L) : I(y.concat(I(x.concat(u), b + F, q)), b + L, q); | |
return q & g(H) ^ q & c ^ g(H) & c; | |
}; | |
}; | |
}()); | |
function SRP() { | |
function a(a) { | |
for (var b = "", c = -1, d, e; ++c < a.length;) d = a.charCodeAt(c), e = c + 1 < a.length ? a.charCodeAt(c + 1) : 0, 55296 <= d && (56319 >= d && 56320 <= e && 57343 >= e) && (d = 65536 + ((d & 1023) << 10) + (e & 1023), c++), 127 >= d ? b += String.fromCharCode(d) : 2047 >= d ? b += String.fromCharCode(192 | d >>> 6 & 31, 128 | d & 63) : 65535 >= d ? b += String.fromCharCode(224 | d >>> 12 & 15, 128 | d >>> 6 & 63, 128 | d & 63) : 2097151 >= d && (b += String.fromCharCode(240 | d >>> 18 & 7, 128 | d >>> 12 & 63, 128 | d >>> 6 & 63, 128 | d & 63)); | |
return b; | |
} | |
function b(a, b, c) { | |
E.error_message(a.status); | |
} | |
function c(a) { | |
f(a.s, a.B).done(function () { | |
$.post(M, {CSRFtoken: $("meta[name=CSRFtoken]").attr("content"), M: K}, h, "json").fail(b); | |
}).fail(function () { | |
a.error ? E.error_message(a.error) : E.error_message("failed"); | |
}); | |
} | |
function e(a, b) { | |
var c = a.toByteArray(), e = b.toByteArray(); | |
c.length > n && c.shift(); | |
e.length > n && e.shift(); | |
for (var f = Array(n - c.length), g = 0, h = f.length; g < h; g++) f[g] = 0; | |
for (var l = Array(n - e.length), g = 0, h = l.length; g < h; g++) l[g] = 0; | |
c = f.concat(c, l, e); | |
return new jsSHA(String.fromCharCode.apply(null, c), "TEXT").getHash("SHA-256", "HEX"); | |
} | |
function f(b, c) { | |
var f = $.Deferred(); | |
if (!b || !c) return f.reject(), f.promise(); | |
var g = new BigInteger(c, 16), h = new BigInteger(e(J, g), 16); | |
if (g.mod(l).equals(BigInteger.ZERO) || h.equals(BigInteger.ZERO)) return f.reject(), f.promise(); | |
var n = new BigInteger(new jsSHA(b + new jsSHA(a(G + ":" + S), "TEXT").getHash("SHA-256", "HEX"), "HEX").getHash("SHA-256", "HEX"), 16); | |
p.modPowPromise(n, l).then(function (a) { | |
return u.multiply(a).mod(l); | |
}).then(function (a) { | |
var b = v.add(h.multiply(n).mod(l)).mod(l); | |
return g.subtract(a).mod(l).modPowPromise(b, l); | |
}).done(function (e) { | |
e = e.toString(16); | |
1 == e.length % 2 && (e = "0" + e); | |
y = new jsSHA(e, "HEX").getHash("SHA-256", "HEX"); | |
e = new jsSHA(a(G), "TEXT").getHash("SHA-256", "HEX"); | |
K = new jsSHA(x + e + b + s + c + y, "HEX").getHash("SHA-256", "HEX"); | |
N = new jsSHA(s + K + y, "HEX").getHash("SHA-256", "HEX"); | |
f.resolve(); | |
}).fail(function () { | |
f.reject(); | |
}); | |
return f.promise(); | |
} | |
function h(a) { | |
a.M && a.M == N.toUpperCase() ? (R = true, E.success()) : a.error ? E.error_message(a.error) : E.error_message("failed"); | |
} | |
function g(a) { | |
a.success ? E.passwordchanged() : a.error ? E.error_message(a.error) : E.error_message("failed"); | |
} | |
var l = new BigInteger("ac6bdb41324a9a9bf166de5e1389582faf72b6651987ee07fc3192943db56050a37329cbb4a099ed8193e0757767a13dd52312ab4b03310dcd7f48a9da04fd50e8083969edb767b0cf6095179a163ab3661a05fbd5faaae82918a9962f0b93b855f97993ec975eeaa80d740adbf4ff747359d041d5c33ea71d281e446b14773bca97b43a23fb801676bd207a436c6481f1d2b9078717461a5b9d32e688f87748544523b524b0d57d5ea77a2775d2ecfa032cfbdbf52fb3786160279004e57ae6af874e7303ce53299ccc041c7bc308d82a5698f3a8d0c38271ae35f8e9dbfbb694b5c803d89f7ae435de236d525f54759b65e372fcd68ef20fa7111f9e4aff73", 16), n = 256, p = new BigInteger("2"), u = new BigInteger("05b9e8ef059c6b32ea59fc1d322d37f04aa30bae5aa9003b8321e21ddb04e300", 16), x = "4a76a9a2402bdd18123389b72ebbda50a30f65aedb90d7273130edea4b29cc4c", r = new SecureRandom, v = new BigInteger(256, r), J = null, s = null, y = null, K = null, N = null, M = "", E = this, R = false, G = "", S = ""; | |
this.identify = function (a, d, e) { | |
function f(a) { | |
a.mod(l).equals(BigInteger.ZERO) ? (v = new BigInteger(256, r), p.modPowPromise(v, l).done(f)) : (J = a, s = J.toString(16), 1 == s.length % 2 && (s = "0" + s), $.post(M, {CSRFtoken: $("meta[name=CSRFtoken]").attr("content"), I: G, A: s}, c, "json").fail(b)); | |
} | |
M = a; | |
G = d; | |
S = e; | |
p.modPowPromise(v, l).done(f); | |
}; | |
this.generateSaltAndVerifierTheCallback = function (b, c, e) { | |
var f = new SecureRandom, g = new BigInteger(32, f).toString(16); | |
1 == g.length % 2 && (g = "0" + g); | |
b = new BigInteger(new jsSHA(g + new jsSHA(a(b + ":" + c), "TEXT").getHash("SHA-256", "HEX"), "HEX").getHash("SHA-256", "HEX"), 16); | |
p.modPowPromise(b, l).done(function (a) { | |
a = a.toString(16); | |
1 == a.length % 2 && (a = "0" + a); | |
e(g, a); | |
}); | |
}; | |
this.generateSaltAndVerifier = function (a, c, d) { | |
M = a; | |
E.generateSaltAndVerifierTheCallback(c, d, function (a, c) { | |
$.post(M, {CSRFtoken: $("meta[name=CSRFtoken]").attr("content"), salt: a, verifier: c}, g, "json").fail(b); | |
}); | |
}; | |
this.success = function () { | |
alert("Login successful."); | |
}; | |
this.passwordchanged = function () { | |
alert("Password changed."); | |
}; | |
this.key = function () { | |
return null != y && R ? y : null; | |
}; | |
this.error_message = function (a) { | |
alert(a); | |
}; | |
} | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment