@builderbot/provider-telegram 1.3.2-y.0 → 1.3.3
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/dist/index.cjs +148 -1713
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -96,7 +96,7 @@ var BigInteger = {exports: {}};
|
|
|
96
96
|
NativeBigInt.prototype = Object.create(Integer.prototype);
|
|
97
97
|
|
|
98
98
|
function isPrecise(n) {
|
|
99
|
-
return -
|
|
99
|
+
return -MAX_INT < n && n < MAX_INT;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
function smallToArray(n) { // For performance reasons doesn't reference BASE, need to change this function if BASE changes
|
|
@@ -1051,7 +1051,7 @@ var BigInteger = {exports: {}};
|
|
|
1051
1051
|
};
|
|
1052
1052
|
SmallInteger.prototype.prev = function () {
|
|
1053
1053
|
var value = this.value;
|
|
1054
|
-
if (value - 1 > -
|
|
1054
|
+
if (value - 1 > -MAX_INT) return new SmallInteger(value - 1);
|
|
1055
1055
|
return new BigInteger(MAX_INT_ARR, true);
|
|
1056
1056
|
};
|
|
1057
1057
|
NativeBigInt.prototype.prev = function () {
|
|
@@ -1153,7 +1153,7 @@ var BigInteger = {exports: {}};
|
|
|
1153
1153
|
};
|
|
1154
1154
|
NativeBigInt.prototype.xor = SmallInteger.prototype.xor = BigInteger.prototype.xor;
|
|
1155
1155
|
|
|
1156
|
-
var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -
|
|
1156
|
+
var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I;
|
|
1157
1157
|
function roughLOB(n) { // get lowestOneBit (rough)
|
|
1158
1158
|
// SmallInteger: return Min(lowestOneBit(n), 1 << 30)
|
|
1159
1159
|
// BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7]
|
|
@@ -32433,7 +32433,11 @@ var ipv4 = {};
|
|
|
32433
32433
|
var common$3 = {};
|
|
32434
32434
|
|
|
32435
32435
|
Object.defineProperty(common$3, "__esModule", { value: true });
|
|
32436
|
-
common$3.
|
|
32436
|
+
common$3.isInSubnet = isInSubnet;
|
|
32437
|
+
common$3.isCorrect = isCorrect;
|
|
32438
|
+
common$3.numberToPaddedHex = numberToPaddedHex;
|
|
32439
|
+
common$3.stringToPaddedHex = stringToPaddedHex;
|
|
32440
|
+
common$3.testBit = testBit;
|
|
32437
32441
|
function isInSubnet(address) {
|
|
32438
32442
|
if (this.subnetMask < address.subnetMask) {
|
|
32439
32443
|
return false;
|
|
@@ -32443,7 +32447,6 @@ function isInSubnet(address) {
|
|
|
32443
32447
|
}
|
|
32444
32448
|
return false;
|
|
32445
32449
|
}
|
|
32446
|
-
common$3.isInSubnet = isInSubnet;
|
|
32447
32450
|
function isCorrect(defaultBits) {
|
|
32448
32451
|
return function () {
|
|
32449
32452
|
if (this.addressMinusSuffix !== this.correctForm()) {
|
|
@@ -32455,7 +32458,24 @@ function isCorrect(defaultBits) {
|
|
|
32455
32458
|
return this.parsedSubnet === String(this.subnetMask);
|
|
32456
32459
|
};
|
|
32457
32460
|
}
|
|
32458
|
-
|
|
32461
|
+
function numberToPaddedHex(number) {
|
|
32462
|
+
return number.toString(16).padStart(2, '0');
|
|
32463
|
+
}
|
|
32464
|
+
function stringToPaddedHex(numberString) {
|
|
32465
|
+
return numberToPaddedHex(parseInt(numberString, 10));
|
|
32466
|
+
}
|
|
32467
|
+
/**
|
|
32468
|
+
* @param binaryValue Binary representation of a value (e.g. `10`)
|
|
32469
|
+
* @param position Byte position, where 0 is the least significant bit
|
|
32470
|
+
*/
|
|
32471
|
+
function testBit(binaryValue, position) {
|
|
32472
|
+
const { length } = binaryValue;
|
|
32473
|
+
if (position > length) {
|
|
32474
|
+
return false;
|
|
32475
|
+
}
|
|
32476
|
+
const positionInString = length - position;
|
|
32477
|
+
return binaryValue.substring(positionInString, positionInString + 1) === '1';
|
|
32478
|
+
}
|
|
32459
32479
|
|
|
32460
32480
|
var constants$2 = {};
|
|
32461
32481
|
|
|
@@ -32474,1599 +32494,11 @@ class AddressError extends Error {
|
|
|
32474
32494
|
constructor(message, parseMessage) {
|
|
32475
32495
|
super(message);
|
|
32476
32496
|
this.name = 'AddressError';
|
|
32477
|
-
|
|
32478
|
-
this.parseMessage = parseMessage;
|
|
32479
|
-
}
|
|
32497
|
+
this.parseMessage = parseMessage;
|
|
32480
32498
|
}
|
|
32481
32499
|
}
|
|
32482
32500
|
addressError.AddressError = AddressError;
|
|
32483
32501
|
|
|
32484
|
-
var jsbn = {exports: {}};
|
|
32485
|
-
|
|
32486
|
-
(function (module, exports) {
|
|
32487
|
-
(function(){
|
|
32488
|
-
|
|
32489
|
-
// Copyright (c) 2005 Tom Wu
|
|
32490
|
-
// All Rights Reserved.
|
|
32491
|
-
// See "LICENSE" for details.
|
|
32492
|
-
|
|
32493
|
-
// Basic JavaScript BN library - subset useful for RSA encryption.
|
|
32494
|
-
|
|
32495
|
-
// Bits per digit
|
|
32496
|
-
var dbits;
|
|
32497
|
-
|
|
32498
|
-
// JavaScript engine analysis
|
|
32499
|
-
var canary = 0xdeadbeefcafe;
|
|
32500
|
-
var j_lm = ((canary&0xffffff)==0xefcafe);
|
|
32501
|
-
|
|
32502
|
-
// (public) Constructor
|
|
32503
|
-
function BigInteger(a,b,c) {
|
|
32504
|
-
if(a != null)
|
|
32505
|
-
if("number" == typeof a) this.fromNumber(a,b,c);
|
|
32506
|
-
else if(b == null && "string" != typeof a) this.fromString(a,256);
|
|
32507
|
-
else this.fromString(a,b);
|
|
32508
|
-
}
|
|
32509
|
-
|
|
32510
|
-
// return new, unset BigInteger
|
|
32511
|
-
function nbi() { return new BigInteger(null); }
|
|
32512
|
-
|
|
32513
|
-
// am: Compute w_j += (x*this_i), propagate carries,
|
|
32514
|
-
// c is initial carry, returns final carry.
|
|
32515
|
-
// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
|
|
32516
|
-
// We need to select the fastest one that works in this environment.
|
|
32517
|
-
|
|
32518
|
-
// am1: use a single mult and divide to get the high bits,
|
|
32519
|
-
// max digit bits should be 26 because
|
|
32520
|
-
// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
|
|
32521
|
-
function am1(i,x,w,j,c,n) {
|
|
32522
|
-
while(--n >= 0) {
|
|
32523
|
-
var v = x*this[i++]+w[j]+c;
|
|
32524
|
-
c = Math.floor(v/0x4000000);
|
|
32525
|
-
w[j++] = v&0x3ffffff;
|
|
32526
|
-
}
|
|
32527
|
-
return c;
|
|
32528
|
-
}
|
|
32529
|
-
// am2 avoids a big mult-and-extract completely.
|
|
32530
|
-
// Max digit bits should be <= 30 because we do bitwise ops
|
|
32531
|
-
// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
|
|
32532
|
-
function am2(i,x,w,j,c,n) {
|
|
32533
|
-
var xl = x&0x7fff, xh = x>>15;
|
|
32534
|
-
while(--n >= 0) {
|
|
32535
|
-
var l = this[i]&0x7fff;
|
|
32536
|
-
var h = this[i++]>>15;
|
|
32537
|
-
var m = xh*l+h*xl;
|
|
32538
|
-
l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);
|
|
32539
|
-
c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
|
|
32540
|
-
w[j++] = l&0x3fffffff;
|
|
32541
|
-
}
|
|
32542
|
-
return c;
|
|
32543
|
-
}
|
|
32544
|
-
// Alternately, set max digit bits to 28 since some
|
|
32545
|
-
// browsers slow down when dealing with 32-bit numbers.
|
|
32546
|
-
function am3(i,x,w,j,c,n) {
|
|
32547
|
-
var xl = x&0x3fff, xh = x>>14;
|
|
32548
|
-
while(--n >= 0) {
|
|
32549
|
-
var l = this[i]&0x3fff;
|
|
32550
|
-
var h = this[i++]>>14;
|
|
32551
|
-
var m = xh*l+h*xl;
|
|
32552
|
-
l = xl*l+((m&0x3fff)<<14)+w[j]+c;
|
|
32553
|
-
c = (l>>28)+(m>>14)+xh*h;
|
|
32554
|
-
w[j++] = l&0xfffffff;
|
|
32555
|
-
}
|
|
32556
|
-
return c;
|
|
32557
|
-
}
|
|
32558
|
-
var inBrowser = typeof navigator !== "undefined";
|
|
32559
|
-
if(inBrowser && j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
|
|
32560
|
-
BigInteger.prototype.am = am2;
|
|
32561
|
-
dbits = 30;
|
|
32562
|
-
}
|
|
32563
|
-
else if(inBrowser && j_lm && (navigator.appName != "Netscape")) {
|
|
32564
|
-
BigInteger.prototype.am = am1;
|
|
32565
|
-
dbits = 26;
|
|
32566
|
-
}
|
|
32567
|
-
else { // Mozilla/Netscape seems to prefer am3
|
|
32568
|
-
BigInteger.prototype.am = am3;
|
|
32569
|
-
dbits = 28;
|
|
32570
|
-
}
|
|
32571
|
-
|
|
32572
|
-
BigInteger.prototype.DB = dbits;
|
|
32573
|
-
BigInteger.prototype.DM = ((1<<dbits)-1);
|
|
32574
|
-
BigInteger.prototype.DV = (1<<dbits);
|
|
32575
|
-
|
|
32576
|
-
var BI_FP = 52;
|
|
32577
|
-
BigInteger.prototype.FV = Math.pow(2,BI_FP);
|
|
32578
|
-
BigInteger.prototype.F1 = BI_FP-dbits;
|
|
32579
|
-
BigInteger.prototype.F2 = 2*dbits-BI_FP;
|
|
32580
|
-
|
|
32581
|
-
// Digit conversions
|
|
32582
|
-
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
32583
|
-
var BI_RC = new Array();
|
|
32584
|
-
var rr,vv;
|
|
32585
|
-
rr = "0".charCodeAt(0);
|
|
32586
|
-
for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
|
|
32587
|
-
rr = "a".charCodeAt(0);
|
|
32588
|
-
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
|
32589
|
-
rr = "A".charCodeAt(0);
|
|
32590
|
-
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
|
32591
|
-
|
|
32592
|
-
function int2char(n) { return BI_RM.charAt(n); }
|
|
32593
|
-
function intAt(s,i) {
|
|
32594
|
-
var c = BI_RC[s.charCodeAt(i)];
|
|
32595
|
-
return (c==null)?-1:c;
|
|
32596
|
-
}
|
|
32597
|
-
|
|
32598
|
-
// (protected) copy this to r
|
|
32599
|
-
function bnpCopyTo(r) {
|
|
32600
|
-
for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
|
|
32601
|
-
r.t = this.t;
|
|
32602
|
-
r.s = this.s;
|
|
32603
|
-
}
|
|
32604
|
-
|
|
32605
|
-
// (protected) set from integer value x, -DV <= x < DV
|
|
32606
|
-
function bnpFromInt(x) {
|
|
32607
|
-
this.t = 1;
|
|
32608
|
-
this.s = (x<0)?-1:0;
|
|
32609
|
-
if(x > 0) this[0] = x;
|
|
32610
|
-
else if(x < -1) this[0] = x+this.DV;
|
|
32611
|
-
else this.t = 0;
|
|
32612
|
-
}
|
|
32613
|
-
|
|
32614
|
-
// return bigint initialized to value
|
|
32615
|
-
function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
|
|
32616
|
-
|
|
32617
|
-
// (protected) set from string and radix
|
|
32618
|
-
function bnpFromString(s,b) {
|
|
32619
|
-
var k;
|
|
32620
|
-
if(b == 16) k = 4;
|
|
32621
|
-
else if(b == 8) k = 3;
|
|
32622
|
-
else if(b == 256) k = 8; // byte array
|
|
32623
|
-
else if(b == 2) k = 1;
|
|
32624
|
-
else if(b == 32) k = 5;
|
|
32625
|
-
else if(b == 4) k = 2;
|
|
32626
|
-
else { this.fromRadix(s,b); return; }
|
|
32627
|
-
this.t = 0;
|
|
32628
|
-
this.s = 0;
|
|
32629
|
-
var i = s.length, mi = false, sh = 0;
|
|
32630
|
-
while(--i >= 0) {
|
|
32631
|
-
var x = (k==8)?s[i]&0xff:intAt(s,i);
|
|
32632
|
-
if(x < 0) {
|
|
32633
|
-
if(s.charAt(i) == "-") mi = true;
|
|
32634
|
-
continue;
|
|
32635
|
-
}
|
|
32636
|
-
mi = false;
|
|
32637
|
-
if(sh == 0)
|
|
32638
|
-
this[this.t++] = x;
|
|
32639
|
-
else if(sh+k > this.DB) {
|
|
32640
|
-
this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh;
|
|
32641
|
-
this[this.t++] = (x>>(this.DB-sh));
|
|
32642
|
-
}
|
|
32643
|
-
else
|
|
32644
|
-
this[this.t-1] |= x<<sh;
|
|
32645
|
-
sh += k;
|
|
32646
|
-
if(sh >= this.DB) sh -= this.DB;
|
|
32647
|
-
}
|
|
32648
|
-
if(k == 8 && (s[0]&0x80) != 0) {
|
|
32649
|
-
this.s = -1;
|
|
32650
|
-
if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh;
|
|
32651
|
-
}
|
|
32652
|
-
this.clamp();
|
|
32653
|
-
if(mi) BigInteger.ZERO.subTo(this,this);
|
|
32654
|
-
}
|
|
32655
|
-
|
|
32656
|
-
// (protected) clamp off excess high words
|
|
32657
|
-
function bnpClamp() {
|
|
32658
|
-
var c = this.s&this.DM;
|
|
32659
|
-
while(this.t > 0 && this[this.t-1] == c) --this.t;
|
|
32660
|
-
}
|
|
32661
|
-
|
|
32662
|
-
// (public) return string representation in given radix
|
|
32663
|
-
function bnToString(b) {
|
|
32664
|
-
if(this.s < 0) return "-"+this.negate().toString(b);
|
|
32665
|
-
var k;
|
|
32666
|
-
if(b == 16) k = 4;
|
|
32667
|
-
else if(b == 8) k = 3;
|
|
32668
|
-
else if(b == 2) k = 1;
|
|
32669
|
-
else if(b == 32) k = 5;
|
|
32670
|
-
else if(b == 4) k = 2;
|
|
32671
|
-
else return this.toRadix(b);
|
|
32672
|
-
var km = (1<<k)-1, d, m = false, r = "", i = this.t;
|
|
32673
|
-
var p = this.DB-(i*this.DB)%k;
|
|
32674
|
-
if(i-- > 0) {
|
|
32675
|
-
if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
|
|
32676
|
-
while(i >= 0) {
|
|
32677
|
-
if(p < k) {
|
|
32678
|
-
d = (this[i]&((1<<p)-1))<<(k-p);
|
|
32679
|
-
d |= this[--i]>>(p+=this.DB-k);
|
|
32680
|
-
}
|
|
32681
|
-
else {
|
|
32682
|
-
d = (this[i]>>(p-=k))&km;
|
|
32683
|
-
if(p <= 0) { p += this.DB; --i; }
|
|
32684
|
-
}
|
|
32685
|
-
if(d > 0) m = true;
|
|
32686
|
-
if(m) r += int2char(d);
|
|
32687
|
-
}
|
|
32688
|
-
}
|
|
32689
|
-
return m?r:"0";
|
|
32690
|
-
}
|
|
32691
|
-
|
|
32692
|
-
// (public) -this
|
|
32693
|
-
function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }
|
|
32694
|
-
|
|
32695
|
-
// (public) |this|
|
|
32696
|
-
function bnAbs() { return (this.s<0)?this.negate():this; }
|
|
32697
|
-
|
|
32698
|
-
// (public) return + if this > a, - if this < a, 0 if equal
|
|
32699
|
-
function bnCompareTo(a) {
|
|
32700
|
-
var r = this.s-a.s;
|
|
32701
|
-
if(r != 0) return r;
|
|
32702
|
-
var i = this.t;
|
|
32703
|
-
r = i-a.t;
|
|
32704
|
-
if(r != 0) return (this.s<0)?-r:r;
|
|
32705
|
-
while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
|
|
32706
|
-
return 0;
|
|
32707
|
-
}
|
|
32708
|
-
|
|
32709
|
-
// returns bit length of the integer x
|
|
32710
|
-
function nbits(x) {
|
|
32711
|
-
var r = 1, t;
|
|
32712
|
-
if((t=x>>>16) != 0) { x = t; r += 16; }
|
|
32713
|
-
if((t=x>>8) != 0) { x = t; r += 8; }
|
|
32714
|
-
if((t=x>>4) != 0) { x = t; r += 4; }
|
|
32715
|
-
if((t=x>>2) != 0) { x = t; r += 2; }
|
|
32716
|
-
if((t=x>>1) != 0) { x = t; r += 1; }
|
|
32717
|
-
return r;
|
|
32718
|
-
}
|
|
32719
|
-
|
|
32720
|
-
// (public) return the number of bits in "this"
|
|
32721
|
-
function bnBitLength() {
|
|
32722
|
-
if(this.t <= 0) return 0;
|
|
32723
|
-
return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));
|
|
32724
|
-
}
|
|
32725
|
-
|
|
32726
|
-
// (protected) r = this << n*DB
|
|
32727
|
-
function bnpDLShiftTo(n,r) {
|
|
32728
|
-
var i;
|
|
32729
|
-
for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
|
|
32730
|
-
for(i = n-1; i >= 0; --i) r[i] = 0;
|
|
32731
|
-
r.t = this.t+n;
|
|
32732
|
-
r.s = this.s;
|
|
32733
|
-
}
|
|
32734
|
-
|
|
32735
|
-
// (protected) r = this >> n*DB
|
|
32736
|
-
function bnpDRShiftTo(n,r) {
|
|
32737
|
-
for(var i = n; i < this.t; ++i) r[i-n] = this[i];
|
|
32738
|
-
r.t = Math.max(this.t-n,0);
|
|
32739
|
-
r.s = this.s;
|
|
32740
|
-
}
|
|
32741
|
-
|
|
32742
|
-
// (protected) r = this << n
|
|
32743
|
-
function bnpLShiftTo(n,r) {
|
|
32744
|
-
var bs = n%this.DB;
|
|
32745
|
-
var cbs = this.DB-bs;
|
|
32746
|
-
var bm = (1<<cbs)-1;
|
|
32747
|
-
var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i;
|
|
32748
|
-
for(i = this.t-1; i >= 0; --i) {
|
|
32749
|
-
r[i+ds+1] = (this[i]>>cbs)|c;
|
|
32750
|
-
c = (this[i]&bm)<<bs;
|
|
32751
|
-
}
|
|
32752
|
-
for(i = ds-1; i >= 0; --i) r[i] = 0;
|
|
32753
|
-
r[ds] = c;
|
|
32754
|
-
r.t = this.t+ds+1;
|
|
32755
|
-
r.s = this.s;
|
|
32756
|
-
r.clamp();
|
|
32757
|
-
}
|
|
32758
|
-
|
|
32759
|
-
// (protected) r = this >> n
|
|
32760
|
-
function bnpRShiftTo(n,r) {
|
|
32761
|
-
r.s = this.s;
|
|
32762
|
-
var ds = Math.floor(n/this.DB);
|
|
32763
|
-
if(ds >= this.t) { r.t = 0; return; }
|
|
32764
|
-
var bs = n%this.DB;
|
|
32765
|
-
var cbs = this.DB-bs;
|
|
32766
|
-
var bm = (1<<bs)-1;
|
|
32767
|
-
r[0] = this[ds]>>bs;
|
|
32768
|
-
for(var i = ds+1; i < this.t; ++i) {
|
|
32769
|
-
r[i-ds-1] |= (this[i]&bm)<<cbs;
|
|
32770
|
-
r[i-ds] = this[i]>>bs;
|
|
32771
|
-
}
|
|
32772
|
-
if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
|
|
32773
|
-
r.t = this.t-ds;
|
|
32774
|
-
r.clamp();
|
|
32775
|
-
}
|
|
32776
|
-
|
|
32777
|
-
// (protected) r = this - a
|
|
32778
|
-
function bnpSubTo(a,r) {
|
|
32779
|
-
var i = 0, c = 0, m = Math.min(a.t,this.t);
|
|
32780
|
-
while(i < m) {
|
|
32781
|
-
c += this[i]-a[i];
|
|
32782
|
-
r[i++] = c&this.DM;
|
|
32783
|
-
c >>= this.DB;
|
|
32784
|
-
}
|
|
32785
|
-
if(a.t < this.t) {
|
|
32786
|
-
c -= a.s;
|
|
32787
|
-
while(i < this.t) {
|
|
32788
|
-
c += this[i];
|
|
32789
|
-
r[i++] = c&this.DM;
|
|
32790
|
-
c >>= this.DB;
|
|
32791
|
-
}
|
|
32792
|
-
c += this.s;
|
|
32793
|
-
}
|
|
32794
|
-
else {
|
|
32795
|
-
c += this.s;
|
|
32796
|
-
while(i < a.t) {
|
|
32797
|
-
c -= a[i];
|
|
32798
|
-
r[i++] = c&this.DM;
|
|
32799
|
-
c >>= this.DB;
|
|
32800
|
-
}
|
|
32801
|
-
c -= a.s;
|
|
32802
|
-
}
|
|
32803
|
-
r.s = (c<0)?-1:0;
|
|
32804
|
-
if(c < -1) r[i++] = this.DV+c;
|
|
32805
|
-
else if(c > 0) r[i++] = c;
|
|
32806
|
-
r.t = i;
|
|
32807
|
-
r.clamp();
|
|
32808
|
-
}
|
|
32809
|
-
|
|
32810
|
-
// (protected) r = this * a, r != this,a (HAC 14.12)
|
|
32811
|
-
// "this" should be the larger one if appropriate.
|
|
32812
|
-
function bnpMultiplyTo(a,r) {
|
|
32813
|
-
var x = this.abs(), y = a.abs();
|
|
32814
|
-
var i = x.t;
|
|
32815
|
-
r.t = i+y.t;
|
|
32816
|
-
while(--i >= 0) r[i] = 0;
|
|
32817
|
-
for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
|
|
32818
|
-
r.s = 0;
|
|
32819
|
-
r.clamp();
|
|
32820
|
-
if(this.s != a.s) BigInteger.ZERO.subTo(r,r);
|
|
32821
|
-
}
|
|
32822
|
-
|
|
32823
|
-
// (protected) r = this^2, r != this (HAC 14.16)
|
|
32824
|
-
function bnpSquareTo(r) {
|
|
32825
|
-
var x = this.abs();
|
|
32826
|
-
var i = r.t = 2*x.t;
|
|
32827
|
-
while(--i >= 0) r[i] = 0;
|
|
32828
|
-
for(i = 0; i < x.t-1; ++i) {
|
|
32829
|
-
var c = x.am(i,x[i],r,2*i,0,1);
|
|
32830
|
-
if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) {
|
|
32831
|
-
r[i+x.t] -= x.DV;
|
|
32832
|
-
r[i+x.t+1] = 1;
|
|
32833
|
-
}
|
|
32834
|
-
}
|
|
32835
|
-
if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
|
|
32836
|
-
r.s = 0;
|
|
32837
|
-
r.clamp();
|
|
32838
|
-
}
|
|
32839
|
-
|
|
32840
|
-
// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
|
|
32841
|
-
// r != q, this != m. q or r may be null.
|
|
32842
|
-
function bnpDivRemTo(m,q,r) {
|
|
32843
|
-
var pm = m.abs();
|
|
32844
|
-
if(pm.t <= 0) return;
|
|
32845
|
-
var pt = this.abs();
|
|
32846
|
-
if(pt.t < pm.t) {
|
|
32847
|
-
if(q != null) q.fromInt(0);
|
|
32848
|
-
if(r != null) this.copyTo(r);
|
|
32849
|
-
return;
|
|
32850
|
-
}
|
|
32851
|
-
if(r == null) r = nbi();
|
|
32852
|
-
var y = nbi(), ts = this.s, ms = m.s;
|
|
32853
|
-
var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus
|
|
32854
|
-
if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); }
|
|
32855
|
-
else { pm.copyTo(y); pt.copyTo(r); }
|
|
32856
|
-
var ys = y.t;
|
|
32857
|
-
var y0 = y[ys-1];
|
|
32858
|
-
if(y0 == 0) return;
|
|
32859
|
-
var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0);
|
|
32860
|
-
var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2;
|
|
32861
|
-
var i = r.t, j = i-ys, t = (q==null)?nbi():q;
|
|
32862
|
-
y.dlShiftTo(j,t);
|
|
32863
|
-
if(r.compareTo(t) >= 0) {
|
|
32864
|
-
r[r.t++] = 1;
|
|
32865
|
-
r.subTo(t,r);
|
|
32866
|
-
}
|
|
32867
|
-
BigInteger.ONE.dlShiftTo(ys,t);
|
|
32868
|
-
t.subTo(y,y); // "negative" y so we can replace sub with am later
|
|
32869
|
-
while(y.t < ys) y[y.t++] = 0;
|
|
32870
|
-
while(--j >= 0) {
|
|
32871
|
-
// Estimate quotient digit
|
|
32872
|
-
var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);
|
|
32873
|
-
if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
|
|
32874
|
-
y.dlShiftTo(j,t);
|
|
32875
|
-
r.subTo(t,r);
|
|
32876
|
-
while(r[i] < --qd) r.subTo(t,r);
|
|
32877
|
-
}
|
|
32878
|
-
}
|
|
32879
|
-
if(q != null) {
|
|
32880
|
-
r.drShiftTo(ys,q);
|
|
32881
|
-
if(ts != ms) BigInteger.ZERO.subTo(q,q);
|
|
32882
|
-
}
|
|
32883
|
-
r.t = ys;
|
|
32884
|
-
r.clamp();
|
|
32885
|
-
if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder
|
|
32886
|
-
if(ts < 0) BigInteger.ZERO.subTo(r,r);
|
|
32887
|
-
}
|
|
32888
|
-
|
|
32889
|
-
// (public) this mod a
|
|
32890
|
-
function bnMod(a) {
|
|
32891
|
-
var r = nbi();
|
|
32892
|
-
this.abs().divRemTo(a,null,r);
|
|
32893
|
-
if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r);
|
|
32894
|
-
return r;
|
|
32895
|
-
}
|
|
32896
|
-
|
|
32897
|
-
// Modular reduction using "classic" algorithm
|
|
32898
|
-
function Classic(m) { this.m = m; }
|
|
32899
|
-
function cConvert(x) {
|
|
32900
|
-
if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
|
|
32901
|
-
else return x;
|
|
32902
|
-
}
|
|
32903
|
-
function cRevert(x) { return x; }
|
|
32904
|
-
function cReduce(x) { x.divRemTo(this.m,null,x); }
|
|
32905
|
-
function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
|
32906
|
-
function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
|
32907
|
-
|
|
32908
|
-
Classic.prototype.convert = cConvert;
|
|
32909
|
-
Classic.prototype.revert = cRevert;
|
|
32910
|
-
Classic.prototype.reduce = cReduce;
|
|
32911
|
-
Classic.prototype.mulTo = cMulTo;
|
|
32912
|
-
Classic.prototype.sqrTo = cSqrTo;
|
|
32913
|
-
|
|
32914
|
-
// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
|
|
32915
|
-
// justification:
|
|
32916
|
-
// xy == 1 (mod m)
|
|
32917
|
-
// xy = 1+km
|
|
32918
|
-
// xy(2-xy) = (1+km)(1-km)
|
|
32919
|
-
// x[y(2-xy)] = 1-k^2m^2
|
|
32920
|
-
// x[y(2-xy)] == 1 (mod m^2)
|
|
32921
|
-
// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
|
|
32922
|
-
// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
|
|
32923
|
-
// JS multiply "overflows" differently from C/C++, so care is needed here.
|
|
32924
|
-
function bnpInvDigit() {
|
|
32925
|
-
if(this.t < 1) return 0;
|
|
32926
|
-
var x = this[0];
|
|
32927
|
-
if((x&1) == 0) return 0;
|
|
32928
|
-
var y = x&3; // y == 1/x mod 2^2
|
|
32929
|
-
y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
|
|
32930
|
-
y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
|
|
32931
|
-
y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
|
|
32932
|
-
// last step - calculate inverse mod DV directly;
|
|
32933
|
-
// assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
|
|
32934
|
-
y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits
|
|
32935
|
-
// we really want the negative inverse, and -DV < y < DV
|
|
32936
|
-
return (y>0)?this.DV-y:-y;
|
|
32937
|
-
}
|
|
32938
|
-
|
|
32939
|
-
// Montgomery reduction
|
|
32940
|
-
function Montgomery(m) {
|
|
32941
|
-
this.m = m;
|
|
32942
|
-
this.mp = m.invDigit();
|
|
32943
|
-
this.mpl = this.mp&0x7fff;
|
|
32944
|
-
this.mph = this.mp>>15;
|
|
32945
|
-
this.um = (1<<(m.DB-15))-1;
|
|
32946
|
-
this.mt2 = 2*m.t;
|
|
32947
|
-
}
|
|
32948
|
-
|
|
32949
|
-
// xR mod m
|
|
32950
|
-
function montConvert(x) {
|
|
32951
|
-
var r = nbi();
|
|
32952
|
-
x.abs().dlShiftTo(this.m.t,r);
|
|
32953
|
-
r.divRemTo(this.m,null,r);
|
|
32954
|
-
if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r);
|
|
32955
|
-
return r;
|
|
32956
|
-
}
|
|
32957
|
-
|
|
32958
|
-
// x/R mod m
|
|
32959
|
-
function montRevert(x) {
|
|
32960
|
-
var r = nbi();
|
|
32961
|
-
x.copyTo(r);
|
|
32962
|
-
this.reduce(r);
|
|
32963
|
-
return r;
|
|
32964
|
-
}
|
|
32965
|
-
|
|
32966
|
-
// x = x/R mod m (HAC 14.32)
|
|
32967
|
-
function montReduce(x) {
|
|
32968
|
-
while(x.t <= this.mt2) // pad x so am has enough room later
|
|
32969
|
-
x[x.t++] = 0;
|
|
32970
|
-
for(var i = 0; i < this.m.t; ++i) {
|
|
32971
|
-
// faster way of calculating u0 = x[i]*mp mod DV
|
|
32972
|
-
var j = x[i]&0x7fff;
|
|
32973
|
-
var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;
|
|
32974
|
-
// use am to combine the multiply-shift-add into one call
|
|
32975
|
-
j = i+this.m.t;
|
|
32976
|
-
x[j] += this.m.am(0,u0,x,i,0,this.m.t);
|
|
32977
|
-
// propagate carry
|
|
32978
|
-
while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; }
|
|
32979
|
-
}
|
|
32980
|
-
x.clamp();
|
|
32981
|
-
x.drShiftTo(this.m.t,x);
|
|
32982
|
-
if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
|
|
32983
|
-
}
|
|
32984
|
-
|
|
32985
|
-
// r = "x^2/R mod m"; x != r
|
|
32986
|
-
function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
|
32987
|
-
|
|
32988
|
-
// r = "xy/R mod m"; x,y != r
|
|
32989
|
-
function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
|
32990
|
-
|
|
32991
|
-
Montgomery.prototype.convert = montConvert;
|
|
32992
|
-
Montgomery.prototype.revert = montRevert;
|
|
32993
|
-
Montgomery.prototype.reduce = montReduce;
|
|
32994
|
-
Montgomery.prototype.mulTo = montMulTo;
|
|
32995
|
-
Montgomery.prototype.sqrTo = montSqrTo;
|
|
32996
|
-
|
|
32997
|
-
// (protected) true iff this is even
|
|
32998
|
-
function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
|
|
32999
|
-
|
|
33000
|
-
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
|
33001
|
-
function bnpExp(e,z) {
|
|
33002
|
-
if(e > 0xffffffff || e < 1) return BigInteger.ONE;
|
|
33003
|
-
var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
|
|
33004
|
-
g.copyTo(r);
|
|
33005
|
-
while(--i >= 0) {
|
|
33006
|
-
z.sqrTo(r,r2);
|
|
33007
|
-
if((e&(1<<i)) > 0) z.mulTo(r2,g,r);
|
|
33008
|
-
else { var t = r; r = r2; r2 = t; }
|
|
33009
|
-
}
|
|
33010
|
-
return z.revert(r);
|
|
33011
|
-
}
|
|
33012
|
-
|
|
33013
|
-
// (public) this^e % m, 0 <= e < 2^32
|
|
33014
|
-
function bnModPowInt(e,m) {
|
|
33015
|
-
var z;
|
|
33016
|
-
if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
|
|
33017
|
-
return this.exp(e,z);
|
|
33018
|
-
}
|
|
33019
|
-
|
|
33020
|
-
// protected
|
|
33021
|
-
BigInteger.prototype.copyTo = bnpCopyTo;
|
|
33022
|
-
BigInteger.prototype.fromInt = bnpFromInt;
|
|
33023
|
-
BigInteger.prototype.fromString = bnpFromString;
|
|
33024
|
-
BigInteger.prototype.clamp = bnpClamp;
|
|
33025
|
-
BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
|
|
33026
|
-
BigInteger.prototype.drShiftTo = bnpDRShiftTo;
|
|
33027
|
-
BigInteger.prototype.lShiftTo = bnpLShiftTo;
|
|
33028
|
-
BigInteger.prototype.rShiftTo = bnpRShiftTo;
|
|
33029
|
-
BigInteger.prototype.subTo = bnpSubTo;
|
|
33030
|
-
BigInteger.prototype.multiplyTo = bnpMultiplyTo;
|
|
33031
|
-
BigInteger.prototype.squareTo = bnpSquareTo;
|
|
33032
|
-
BigInteger.prototype.divRemTo = bnpDivRemTo;
|
|
33033
|
-
BigInteger.prototype.invDigit = bnpInvDigit;
|
|
33034
|
-
BigInteger.prototype.isEven = bnpIsEven;
|
|
33035
|
-
BigInteger.prototype.exp = bnpExp;
|
|
33036
|
-
|
|
33037
|
-
// public
|
|
33038
|
-
BigInteger.prototype.toString = bnToString;
|
|
33039
|
-
BigInteger.prototype.negate = bnNegate;
|
|
33040
|
-
BigInteger.prototype.abs = bnAbs;
|
|
33041
|
-
BigInteger.prototype.compareTo = bnCompareTo;
|
|
33042
|
-
BigInteger.prototype.bitLength = bnBitLength;
|
|
33043
|
-
BigInteger.prototype.mod = bnMod;
|
|
33044
|
-
BigInteger.prototype.modPowInt = bnModPowInt;
|
|
33045
|
-
|
|
33046
|
-
// "constants"
|
|
33047
|
-
BigInteger.ZERO = nbv(0);
|
|
33048
|
-
BigInteger.ONE = nbv(1);
|
|
33049
|
-
|
|
33050
|
-
// Copyright (c) 2005-2009 Tom Wu
|
|
33051
|
-
// All Rights Reserved.
|
|
33052
|
-
// See "LICENSE" for details.
|
|
33053
|
-
|
|
33054
|
-
// Extended JavaScript BN functions, required for RSA private ops.
|
|
33055
|
-
|
|
33056
|
-
// Version 1.1: new BigInteger("0", 10) returns "proper" zero
|
|
33057
|
-
// Version 1.2: square() API, isProbablePrime fix
|
|
33058
|
-
|
|
33059
|
-
// (public)
|
|
33060
|
-
function bnClone() { var r = nbi(); this.copyTo(r); return r; }
|
|
33061
|
-
|
|
33062
|
-
// (public) return value as integer
|
|
33063
|
-
function bnIntValue() {
|
|
33064
|
-
if(this.s < 0) {
|
|
33065
|
-
if(this.t == 1) return this[0]-this.DV;
|
|
33066
|
-
else if(this.t == 0) return -1;
|
|
33067
|
-
}
|
|
33068
|
-
else if(this.t == 1) return this[0];
|
|
33069
|
-
else if(this.t == 0) return 0;
|
|
33070
|
-
// assumes 16 < DB < 32
|
|
33071
|
-
return ((this[1]&((1<<(32-this.DB))-1))<<this.DB)|this[0];
|
|
33072
|
-
}
|
|
33073
|
-
|
|
33074
|
-
// (public) return value as byte
|
|
33075
|
-
function bnByteValue() { return (this.t==0)?this.s:(this[0]<<24)>>24; }
|
|
33076
|
-
|
|
33077
|
-
// (public) return value as short (assumes DB>=16)
|
|
33078
|
-
function bnShortValue() { return (this.t==0)?this.s:(this[0]<<16)>>16; }
|
|
33079
|
-
|
|
33080
|
-
// (protected) return x s.t. r^x < DV
|
|
33081
|
-
function bnpChunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); }
|
|
33082
|
-
|
|
33083
|
-
// (public) 0 if this == 0, 1 if this > 0
|
|
33084
|
-
function bnSigNum() {
|
|
33085
|
-
if(this.s < 0) return -1;
|
|
33086
|
-
else if(this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0;
|
|
33087
|
-
else return 1;
|
|
33088
|
-
}
|
|
33089
|
-
|
|
33090
|
-
// (protected) convert to radix string
|
|
33091
|
-
function bnpToRadix(b) {
|
|
33092
|
-
if(b == null) b = 10;
|
|
33093
|
-
if(this.signum() == 0 || b < 2 || b > 36) return "0";
|
|
33094
|
-
var cs = this.chunkSize(b);
|
|
33095
|
-
var a = Math.pow(b,cs);
|
|
33096
|
-
var d = nbv(a), y = nbi(), z = nbi(), r = "";
|
|
33097
|
-
this.divRemTo(d,y,z);
|
|
33098
|
-
while(y.signum() > 0) {
|
|
33099
|
-
r = (a+z.intValue()).toString(b).substr(1) + r;
|
|
33100
|
-
y.divRemTo(d,y,z);
|
|
33101
|
-
}
|
|
33102
|
-
return z.intValue().toString(b) + r;
|
|
33103
|
-
}
|
|
33104
|
-
|
|
33105
|
-
// (protected) convert from radix string
|
|
33106
|
-
function bnpFromRadix(s,b) {
|
|
33107
|
-
this.fromInt(0);
|
|
33108
|
-
if(b == null) b = 10;
|
|
33109
|
-
var cs = this.chunkSize(b);
|
|
33110
|
-
var d = Math.pow(b,cs), mi = false, j = 0, w = 0;
|
|
33111
|
-
for(var i = 0; i < s.length; ++i) {
|
|
33112
|
-
var x = intAt(s,i);
|
|
33113
|
-
if(x < 0) {
|
|
33114
|
-
if(s.charAt(i) == "-" && this.signum() == 0) mi = true;
|
|
33115
|
-
continue;
|
|
33116
|
-
}
|
|
33117
|
-
w = b*w+x;
|
|
33118
|
-
if(++j >= cs) {
|
|
33119
|
-
this.dMultiply(d);
|
|
33120
|
-
this.dAddOffset(w,0);
|
|
33121
|
-
j = 0;
|
|
33122
|
-
w = 0;
|
|
33123
|
-
}
|
|
33124
|
-
}
|
|
33125
|
-
if(j > 0) {
|
|
33126
|
-
this.dMultiply(Math.pow(b,j));
|
|
33127
|
-
this.dAddOffset(w,0);
|
|
33128
|
-
}
|
|
33129
|
-
if(mi) BigInteger.ZERO.subTo(this,this);
|
|
33130
|
-
}
|
|
33131
|
-
|
|
33132
|
-
// (protected) alternate constructor
|
|
33133
|
-
function bnpFromNumber(a,b,c) {
|
|
33134
|
-
if("number" == typeof b) {
|
|
33135
|
-
// new BigInteger(int,int,RNG)
|
|
33136
|
-
if(a < 2) this.fromInt(1);
|
|
33137
|
-
else {
|
|
33138
|
-
this.fromNumber(a,c);
|
|
33139
|
-
if(!this.testBit(a-1)) // force MSB set
|
|
33140
|
-
this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this);
|
|
33141
|
-
if(this.isEven()) this.dAddOffset(1,0); // force odd
|
|
33142
|
-
while(!this.isProbablePrime(b)) {
|
|
33143
|
-
this.dAddOffset(2,0);
|
|
33144
|
-
if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this);
|
|
33145
|
-
}
|
|
33146
|
-
}
|
|
33147
|
-
}
|
|
33148
|
-
else {
|
|
33149
|
-
// new BigInteger(int,RNG)
|
|
33150
|
-
var x = new Array(), t = a&7;
|
|
33151
|
-
x.length = (a>>3)+1;
|
|
33152
|
-
b.nextBytes(x);
|
|
33153
|
-
if(t > 0) x[0] &= ((1<<t)-1); else x[0] = 0;
|
|
33154
|
-
this.fromString(x,256);
|
|
33155
|
-
}
|
|
33156
|
-
}
|
|
33157
|
-
|
|
33158
|
-
// (public) convert to bigendian byte array
|
|
33159
|
-
function bnToByteArray() {
|
|
33160
|
-
var i = this.t, r = new Array();
|
|
33161
|
-
r[0] = this.s;
|
|
33162
|
-
var p = this.DB-(i*this.DB)%8, d, k = 0;
|
|
33163
|
-
if(i-- > 0) {
|
|
33164
|
-
if(p < this.DB && (d = this[i]>>p) != (this.s&this.DM)>>p)
|
|
33165
|
-
r[k++] = d|(this.s<<(this.DB-p));
|
|
33166
|
-
while(i >= 0) {
|
|
33167
|
-
if(p < 8) {
|
|
33168
|
-
d = (this[i]&((1<<p)-1))<<(8-p);
|
|
33169
|
-
d |= this[--i]>>(p+=this.DB-8);
|
|
33170
|
-
}
|
|
33171
|
-
else {
|
|
33172
|
-
d = (this[i]>>(p-=8))&0xff;
|
|
33173
|
-
if(p <= 0) { p += this.DB; --i; }
|
|
33174
|
-
}
|
|
33175
|
-
if((d&0x80) != 0) d |= -256;
|
|
33176
|
-
if(k == 0 && (this.s&0x80) != (d&0x80)) ++k;
|
|
33177
|
-
if(k > 0 || d != this.s) r[k++] = d;
|
|
33178
|
-
}
|
|
33179
|
-
}
|
|
33180
|
-
return r;
|
|
33181
|
-
}
|
|
33182
|
-
|
|
33183
|
-
function bnEquals(a) { return(this.compareTo(a)==0); }
|
|
33184
|
-
function bnMin(a) { return (this.compareTo(a)<0)?this:a; }
|
|
33185
|
-
function bnMax(a) { return (this.compareTo(a)>0)?this:a; }
|
|
33186
|
-
|
|
33187
|
-
// (protected) r = this op a (bitwise)
|
|
33188
|
-
function bnpBitwiseTo(a,op,r) {
|
|
33189
|
-
var i, f, m = Math.min(a.t,this.t);
|
|
33190
|
-
for(i = 0; i < m; ++i) r[i] = op(this[i],a[i]);
|
|
33191
|
-
if(a.t < this.t) {
|
|
33192
|
-
f = a.s&this.DM;
|
|
33193
|
-
for(i = m; i < this.t; ++i) r[i] = op(this[i],f);
|
|
33194
|
-
r.t = this.t;
|
|
33195
|
-
}
|
|
33196
|
-
else {
|
|
33197
|
-
f = this.s&this.DM;
|
|
33198
|
-
for(i = m; i < a.t; ++i) r[i] = op(f,a[i]);
|
|
33199
|
-
r.t = a.t;
|
|
33200
|
-
}
|
|
33201
|
-
r.s = op(this.s,a.s);
|
|
33202
|
-
r.clamp();
|
|
33203
|
-
}
|
|
33204
|
-
|
|
33205
|
-
// (public) this & a
|
|
33206
|
-
function op_and(x,y) { return x&y; }
|
|
33207
|
-
function bnAnd(a) { var r = nbi(); this.bitwiseTo(a,op_and,r); return r; }
|
|
33208
|
-
|
|
33209
|
-
// (public) this | a
|
|
33210
|
-
function op_or(x,y) { return x|y; }
|
|
33211
|
-
function bnOr(a) { var r = nbi(); this.bitwiseTo(a,op_or,r); return r; }
|
|
33212
|
-
|
|
33213
|
-
// (public) this ^ a
|
|
33214
|
-
function op_xor(x,y) { return x^y; }
|
|
33215
|
-
function bnXor(a) { var r = nbi(); this.bitwiseTo(a,op_xor,r); return r; }
|
|
33216
|
-
|
|
33217
|
-
// (public) this & ~a
|
|
33218
|
-
function op_andnot(x,y) { return x&~y; }
|
|
33219
|
-
function bnAndNot(a) { var r = nbi(); this.bitwiseTo(a,op_andnot,r); return r; }
|
|
33220
|
-
|
|
33221
|
-
// (public) ~this
|
|
33222
|
-
function bnNot() {
|
|
33223
|
-
var r = nbi();
|
|
33224
|
-
for(var i = 0; i < this.t; ++i) r[i] = this.DM&~this[i];
|
|
33225
|
-
r.t = this.t;
|
|
33226
|
-
r.s = ~this.s;
|
|
33227
|
-
return r;
|
|
33228
|
-
}
|
|
33229
|
-
|
|
33230
|
-
// (public) this << n
|
|
33231
|
-
function bnShiftLeft(n) {
|
|
33232
|
-
var r = nbi();
|
|
33233
|
-
if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r);
|
|
33234
|
-
return r;
|
|
33235
|
-
}
|
|
33236
|
-
|
|
33237
|
-
// (public) this >> n
|
|
33238
|
-
function bnShiftRight(n) {
|
|
33239
|
-
var r = nbi();
|
|
33240
|
-
if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r);
|
|
33241
|
-
return r;
|
|
33242
|
-
}
|
|
33243
|
-
|
|
33244
|
-
// return index of lowest 1-bit in x, x < 2^31
|
|
33245
|
-
function lbit(x) {
|
|
33246
|
-
if(x == 0) return -1;
|
|
33247
|
-
var r = 0;
|
|
33248
|
-
if((x&0xffff) == 0) { x >>= 16; r += 16; }
|
|
33249
|
-
if((x&0xff) == 0) { x >>= 8; r += 8; }
|
|
33250
|
-
if((x&0xf) == 0) { x >>= 4; r += 4; }
|
|
33251
|
-
if((x&3) == 0) { x >>= 2; r += 2; }
|
|
33252
|
-
if((x&1) == 0) ++r;
|
|
33253
|
-
return r;
|
|
33254
|
-
}
|
|
33255
|
-
|
|
33256
|
-
// (public) returns index of lowest 1-bit (or -1 if none)
|
|
33257
|
-
function bnGetLowestSetBit() {
|
|
33258
|
-
for(var i = 0; i < this.t; ++i)
|
|
33259
|
-
if(this[i] != 0) return i*this.DB+lbit(this[i]);
|
|
33260
|
-
if(this.s < 0) return this.t*this.DB;
|
|
33261
|
-
return -1;
|
|
33262
|
-
}
|
|
33263
|
-
|
|
33264
|
-
// return number of 1 bits in x
|
|
33265
|
-
function cbit(x) {
|
|
33266
|
-
var r = 0;
|
|
33267
|
-
while(x != 0) { x &= x-1; ++r; }
|
|
33268
|
-
return r;
|
|
33269
|
-
}
|
|
33270
|
-
|
|
33271
|
-
// (public) return number of set bits
|
|
33272
|
-
function bnBitCount() {
|
|
33273
|
-
var r = 0, x = this.s&this.DM;
|
|
33274
|
-
for(var i = 0; i < this.t; ++i) r += cbit(this[i]^x);
|
|
33275
|
-
return r;
|
|
33276
|
-
}
|
|
33277
|
-
|
|
33278
|
-
// (public) true iff nth bit is set
|
|
33279
|
-
function bnTestBit(n) {
|
|
33280
|
-
var j = Math.floor(n/this.DB);
|
|
33281
|
-
if(j >= this.t) return(this.s!=0);
|
|
33282
|
-
return((this[j]&(1<<(n%this.DB)))!=0);
|
|
33283
|
-
}
|
|
33284
|
-
|
|
33285
|
-
// (protected) this op (1<<n)
|
|
33286
|
-
function bnpChangeBit(n,op) {
|
|
33287
|
-
var r = BigInteger.ONE.shiftLeft(n);
|
|
33288
|
-
this.bitwiseTo(r,op,r);
|
|
33289
|
-
return r;
|
|
33290
|
-
}
|
|
33291
|
-
|
|
33292
|
-
// (public) this | (1<<n)
|
|
33293
|
-
function bnSetBit(n) { return this.changeBit(n,op_or); }
|
|
33294
|
-
|
|
33295
|
-
// (public) this & ~(1<<n)
|
|
33296
|
-
function bnClearBit(n) { return this.changeBit(n,op_andnot); }
|
|
33297
|
-
|
|
33298
|
-
// (public) this ^ (1<<n)
|
|
33299
|
-
function bnFlipBit(n) { return this.changeBit(n,op_xor); }
|
|
33300
|
-
|
|
33301
|
-
// (protected) r = this + a
|
|
33302
|
-
function bnpAddTo(a,r) {
|
|
33303
|
-
var i = 0, c = 0, m = Math.min(a.t,this.t);
|
|
33304
|
-
while(i < m) {
|
|
33305
|
-
c += this[i]+a[i];
|
|
33306
|
-
r[i++] = c&this.DM;
|
|
33307
|
-
c >>= this.DB;
|
|
33308
|
-
}
|
|
33309
|
-
if(a.t < this.t) {
|
|
33310
|
-
c += a.s;
|
|
33311
|
-
while(i < this.t) {
|
|
33312
|
-
c += this[i];
|
|
33313
|
-
r[i++] = c&this.DM;
|
|
33314
|
-
c >>= this.DB;
|
|
33315
|
-
}
|
|
33316
|
-
c += this.s;
|
|
33317
|
-
}
|
|
33318
|
-
else {
|
|
33319
|
-
c += this.s;
|
|
33320
|
-
while(i < a.t) {
|
|
33321
|
-
c += a[i];
|
|
33322
|
-
r[i++] = c&this.DM;
|
|
33323
|
-
c >>= this.DB;
|
|
33324
|
-
}
|
|
33325
|
-
c += a.s;
|
|
33326
|
-
}
|
|
33327
|
-
r.s = (c<0)?-1:0;
|
|
33328
|
-
if(c > 0) r[i++] = c;
|
|
33329
|
-
else if(c < -1) r[i++] = this.DV+c;
|
|
33330
|
-
r.t = i;
|
|
33331
|
-
r.clamp();
|
|
33332
|
-
}
|
|
33333
|
-
|
|
33334
|
-
// (public) this + a
|
|
33335
|
-
function bnAdd(a) { var r = nbi(); this.addTo(a,r); return r; }
|
|
33336
|
-
|
|
33337
|
-
// (public) this - a
|
|
33338
|
-
function bnSubtract(a) { var r = nbi(); this.subTo(a,r); return r; }
|
|
33339
|
-
|
|
33340
|
-
// (public) this * a
|
|
33341
|
-
function bnMultiply(a) { var r = nbi(); this.multiplyTo(a,r); return r; }
|
|
33342
|
-
|
|
33343
|
-
// (public) this^2
|
|
33344
|
-
function bnSquare() { var r = nbi(); this.squareTo(r); return r; }
|
|
33345
|
-
|
|
33346
|
-
// (public) this / a
|
|
33347
|
-
function bnDivide(a) { var r = nbi(); this.divRemTo(a,r,null); return r; }
|
|
33348
|
-
|
|
33349
|
-
// (public) this % a
|
|
33350
|
-
function bnRemainder(a) { var r = nbi(); this.divRemTo(a,null,r); return r; }
|
|
33351
|
-
|
|
33352
|
-
// (public) [this/a,this%a]
|
|
33353
|
-
function bnDivideAndRemainder(a) {
|
|
33354
|
-
var q = nbi(), r = nbi();
|
|
33355
|
-
this.divRemTo(a,q,r);
|
|
33356
|
-
return new Array(q,r);
|
|
33357
|
-
}
|
|
33358
|
-
|
|
33359
|
-
// (protected) this *= n, this >= 0, 1 < n < DV
|
|
33360
|
-
function bnpDMultiply(n) {
|
|
33361
|
-
this[this.t] = this.am(0,n-1,this,0,0,this.t);
|
|
33362
|
-
++this.t;
|
|
33363
|
-
this.clamp();
|
|
33364
|
-
}
|
|
33365
|
-
|
|
33366
|
-
// (protected) this += n << w words, this >= 0
|
|
33367
|
-
function bnpDAddOffset(n,w) {
|
|
33368
|
-
if(n == 0) return;
|
|
33369
|
-
while(this.t <= w) this[this.t++] = 0;
|
|
33370
|
-
this[w] += n;
|
|
33371
|
-
while(this[w] >= this.DV) {
|
|
33372
|
-
this[w] -= this.DV;
|
|
33373
|
-
if(++w >= this.t) this[this.t++] = 0;
|
|
33374
|
-
++this[w];
|
|
33375
|
-
}
|
|
33376
|
-
}
|
|
33377
|
-
|
|
33378
|
-
// A "null" reducer
|
|
33379
|
-
function NullExp() {}
|
|
33380
|
-
function nNop(x) { return x; }
|
|
33381
|
-
function nMulTo(x,y,r) { x.multiplyTo(y,r); }
|
|
33382
|
-
function nSqrTo(x,r) { x.squareTo(r); }
|
|
33383
|
-
|
|
33384
|
-
NullExp.prototype.convert = nNop;
|
|
33385
|
-
NullExp.prototype.revert = nNop;
|
|
33386
|
-
NullExp.prototype.mulTo = nMulTo;
|
|
33387
|
-
NullExp.prototype.sqrTo = nSqrTo;
|
|
33388
|
-
|
|
33389
|
-
// (public) this^e
|
|
33390
|
-
function bnPow(e) { return this.exp(e,new NullExp()); }
|
|
33391
|
-
|
|
33392
|
-
// (protected) r = lower n words of "this * a", a.t <= n
|
|
33393
|
-
// "this" should be the larger one if appropriate.
|
|
33394
|
-
function bnpMultiplyLowerTo(a,n,r) {
|
|
33395
|
-
var i = Math.min(this.t+a.t,n);
|
|
33396
|
-
r.s = 0; // assumes a,this >= 0
|
|
33397
|
-
r.t = i;
|
|
33398
|
-
while(i > 0) r[--i] = 0;
|
|
33399
|
-
var j;
|
|
33400
|
-
for(j = r.t-this.t; i < j; ++i) r[i+this.t] = this.am(0,a[i],r,i,0,this.t);
|
|
33401
|
-
for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a[i],r,i,0,n-i);
|
|
33402
|
-
r.clamp();
|
|
33403
|
-
}
|
|
33404
|
-
|
|
33405
|
-
// (protected) r = "this * a" without lower n words, n > 0
|
|
33406
|
-
// "this" should be the larger one if appropriate.
|
|
33407
|
-
function bnpMultiplyUpperTo(a,n,r) {
|
|
33408
|
-
--n;
|
|
33409
|
-
var i = r.t = this.t+a.t-n;
|
|
33410
|
-
r.s = 0; // assumes a,this >= 0
|
|
33411
|
-
while(--i >= 0) r[i] = 0;
|
|
33412
|
-
for(i = Math.max(n-this.t,0); i < a.t; ++i)
|
|
33413
|
-
r[this.t+i-n] = this.am(n-i,a[i],r,0,0,this.t+i-n);
|
|
33414
|
-
r.clamp();
|
|
33415
|
-
r.drShiftTo(1,r);
|
|
33416
|
-
}
|
|
33417
|
-
|
|
33418
|
-
// Barrett modular reduction
|
|
33419
|
-
function Barrett(m) {
|
|
33420
|
-
// setup Barrett
|
|
33421
|
-
this.r2 = nbi();
|
|
33422
|
-
this.q3 = nbi();
|
|
33423
|
-
BigInteger.ONE.dlShiftTo(2*m.t,this.r2);
|
|
33424
|
-
this.mu = this.r2.divide(m);
|
|
33425
|
-
this.m = m;
|
|
33426
|
-
}
|
|
33427
|
-
|
|
33428
|
-
function barrettConvert(x) {
|
|
33429
|
-
if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m);
|
|
33430
|
-
else if(x.compareTo(this.m) < 0) return x;
|
|
33431
|
-
else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; }
|
|
33432
|
-
}
|
|
33433
|
-
|
|
33434
|
-
function barrettRevert(x) { return x; }
|
|
33435
|
-
|
|
33436
|
-
// x = x mod m (HAC 14.42)
|
|
33437
|
-
function barrettReduce(x) {
|
|
33438
|
-
x.drShiftTo(this.m.t-1,this.r2);
|
|
33439
|
-
if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); }
|
|
33440
|
-
this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);
|
|
33441
|
-
this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);
|
|
33442
|
-
while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1);
|
|
33443
|
-
x.subTo(this.r2,x);
|
|
33444
|
-
while(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
|
|
33445
|
-
}
|
|
33446
|
-
|
|
33447
|
-
// r = x^2 mod m; x != r
|
|
33448
|
-
function barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
|
33449
|
-
|
|
33450
|
-
// r = x*y mod m; x,y != r
|
|
33451
|
-
function barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
|
33452
|
-
|
|
33453
|
-
Barrett.prototype.convert = barrettConvert;
|
|
33454
|
-
Barrett.prototype.revert = barrettRevert;
|
|
33455
|
-
Barrett.prototype.reduce = barrettReduce;
|
|
33456
|
-
Barrett.prototype.mulTo = barrettMulTo;
|
|
33457
|
-
Barrett.prototype.sqrTo = barrettSqrTo;
|
|
33458
|
-
|
|
33459
|
-
// (public) this^e % m (HAC 14.85)
|
|
33460
|
-
function bnModPow(e,m) {
|
|
33461
|
-
var i = e.bitLength(), k, r = nbv(1), z;
|
|
33462
|
-
if(i <= 0) return r;
|
|
33463
|
-
else if(i < 18) k = 1;
|
|
33464
|
-
else if(i < 48) k = 3;
|
|
33465
|
-
else if(i < 144) k = 4;
|
|
33466
|
-
else if(i < 768) k = 5;
|
|
33467
|
-
else k = 6;
|
|
33468
|
-
if(i < 8)
|
|
33469
|
-
z = new Classic(m);
|
|
33470
|
-
else if(m.isEven())
|
|
33471
|
-
z = new Barrett(m);
|
|
33472
|
-
else
|
|
33473
|
-
z = new Montgomery(m);
|
|
33474
|
-
|
|
33475
|
-
// precomputation
|
|
33476
|
-
var g = new Array(), n = 3, k1 = k-1, km = (1<<k)-1;
|
|
33477
|
-
g[1] = z.convert(this);
|
|
33478
|
-
if(k > 1) {
|
|
33479
|
-
var g2 = nbi();
|
|
33480
|
-
z.sqrTo(g[1],g2);
|
|
33481
|
-
while(n <= km) {
|
|
33482
|
-
g[n] = nbi();
|
|
33483
|
-
z.mulTo(g2,g[n-2],g[n]);
|
|
33484
|
-
n += 2;
|
|
33485
|
-
}
|
|
33486
|
-
}
|
|
33487
|
-
|
|
33488
|
-
var j = e.t-1, w, is1 = true, r2 = nbi(), t;
|
|
33489
|
-
i = nbits(e[j])-1;
|
|
33490
|
-
while(j >= 0) {
|
|
33491
|
-
if(i >= k1) w = (e[j]>>(i-k1))&km;
|
|
33492
|
-
else {
|
|
33493
|
-
w = (e[j]&((1<<(i+1))-1))<<(k1-i);
|
|
33494
|
-
if(j > 0) w |= e[j-1]>>(this.DB+i-k1);
|
|
33495
|
-
}
|
|
33496
|
-
|
|
33497
|
-
n = k;
|
|
33498
|
-
while((w&1) == 0) { w >>= 1; --n; }
|
|
33499
|
-
if((i -= n) < 0) { i += this.DB; --j; }
|
|
33500
|
-
if(is1) { // ret == 1, don't bother squaring or multiplying it
|
|
33501
|
-
g[w].copyTo(r);
|
|
33502
|
-
is1 = false;
|
|
33503
|
-
}
|
|
33504
|
-
else {
|
|
33505
|
-
while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; }
|
|
33506
|
-
if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; }
|
|
33507
|
-
z.mulTo(r2,g[w],r);
|
|
33508
|
-
}
|
|
33509
|
-
|
|
33510
|
-
while(j >= 0 && (e[j]&(1<<i)) == 0) {
|
|
33511
|
-
z.sqrTo(r,r2); t = r; r = r2; r2 = t;
|
|
33512
|
-
if(--i < 0) { i = this.DB-1; --j; }
|
|
33513
|
-
}
|
|
33514
|
-
}
|
|
33515
|
-
return z.revert(r);
|
|
33516
|
-
}
|
|
33517
|
-
|
|
33518
|
-
// (public) gcd(this,a) (HAC 14.54)
|
|
33519
|
-
function bnGCD(a) {
|
|
33520
|
-
var x = (this.s<0)?this.negate():this.clone();
|
|
33521
|
-
var y = (a.s<0)?a.negate():a.clone();
|
|
33522
|
-
if(x.compareTo(y) < 0) { var t = x; x = y; y = t; }
|
|
33523
|
-
var i = x.getLowestSetBit(), g = y.getLowestSetBit();
|
|
33524
|
-
if(g < 0) return x;
|
|
33525
|
-
if(i < g) g = i;
|
|
33526
|
-
if(g > 0) {
|
|
33527
|
-
x.rShiftTo(g,x);
|
|
33528
|
-
y.rShiftTo(g,y);
|
|
33529
|
-
}
|
|
33530
|
-
while(x.signum() > 0) {
|
|
33531
|
-
if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x);
|
|
33532
|
-
if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y);
|
|
33533
|
-
if(x.compareTo(y) >= 0) {
|
|
33534
|
-
x.subTo(y,x);
|
|
33535
|
-
x.rShiftTo(1,x);
|
|
33536
|
-
}
|
|
33537
|
-
else {
|
|
33538
|
-
y.subTo(x,y);
|
|
33539
|
-
y.rShiftTo(1,y);
|
|
33540
|
-
}
|
|
33541
|
-
}
|
|
33542
|
-
if(g > 0) y.lShiftTo(g,y);
|
|
33543
|
-
return y;
|
|
33544
|
-
}
|
|
33545
|
-
|
|
33546
|
-
// (protected) this % n, n < 2^26
|
|
33547
|
-
function bnpModInt(n) {
|
|
33548
|
-
if(n <= 0) return 0;
|
|
33549
|
-
var d = this.DV%n, r = (this.s<0)?n-1:0;
|
|
33550
|
-
if(this.t > 0)
|
|
33551
|
-
if(d == 0) r = this[0]%n;
|
|
33552
|
-
else for(var i = this.t-1; i >= 0; --i) r = (d*r+this[i])%n;
|
|
33553
|
-
return r;
|
|
33554
|
-
}
|
|
33555
|
-
|
|
33556
|
-
// (public) 1/this % m (HAC 14.61)
|
|
33557
|
-
function bnModInverse(m) {
|
|
33558
|
-
var ac = m.isEven();
|
|
33559
|
-
if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO;
|
|
33560
|
-
var u = m.clone(), v = this.clone();
|
|
33561
|
-
var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1);
|
|
33562
|
-
while(u.signum() != 0) {
|
|
33563
|
-
while(u.isEven()) {
|
|
33564
|
-
u.rShiftTo(1,u);
|
|
33565
|
-
if(ac) {
|
|
33566
|
-
if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); }
|
|
33567
|
-
a.rShiftTo(1,a);
|
|
33568
|
-
}
|
|
33569
|
-
else if(!b.isEven()) b.subTo(m,b);
|
|
33570
|
-
b.rShiftTo(1,b);
|
|
33571
|
-
}
|
|
33572
|
-
while(v.isEven()) {
|
|
33573
|
-
v.rShiftTo(1,v);
|
|
33574
|
-
if(ac) {
|
|
33575
|
-
if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); }
|
|
33576
|
-
c.rShiftTo(1,c);
|
|
33577
|
-
}
|
|
33578
|
-
else if(!d.isEven()) d.subTo(m,d);
|
|
33579
|
-
d.rShiftTo(1,d);
|
|
33580
|
-
}
|
|
33581
|
-
if(u.compareTo(v) >= 0) {
|
|
33582
|
-
u.subTo(v,u);
|
|
33583
|
-
if(ac) a.subTo(c,a);
|
|
33584
|
-
b.subTo(d,b);
|
|
33585
|
-
}
|
|
33586
|
-
else {
|
|
33587
|
-
v.subTo(u,v);
|
|
33588
|
-
if(ac) c.subTo(a,c);
|
|
33589
|
-
d.subTo(b,d);
|
|
33590
|
-
}
|
|
33591
|
-
}
|
|
33592
|
-
if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO;
|
|
33593
|
-
if(d.compareTo(m) >= 0) return d.subtract(m);
|
|
33594
|
-
if(d.signum() < 0) d.addTo(m,d); else return d;
|
|
33595
|
-
if(d.signum() < 0) return d.add(m); else return d;
|
|
33596
|
-
}
|
|
33597
|
-
|
|
33598
|
-
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];
|
|
33599
|
-
var lplim = (1<<26)/lowprimes[lowprimes.length-1];
|
|
33600
|
-
|
|
33601
|
-
// (public) test primality with certainty >= 1-.5^t
|
|
33602
|
-
function bnIsProbablePrime(t) {
|
|
33603
|
-
var i, x = this.abs();
|
|
33604
|
-
if(x.t == 1 && x[0] <= lowprimes[lowprimes.length-1]) {
|
|
33605
|
-
for(i = 0; i < lowprimes.length; ++i)
|
|
33606
|
-
if(x[0] == lowprimes[i]) return true;
|
|
33607
|
-
return false;
|
|
33608
|
-
}
|
|
33609
|
-
if(x.isEven()) return false;
|
|
33610
|
-
i = 1;
|
|
33611
|
-
while(i < lowprimes.length) {
|
|
33612
|
-
var m = lowprimes[i], j = i+1;
|
|
33613
|
-
while(j < lowprimes.length && m < lplim) m *= lowprimes[j++];
|
|
33614
|
-
m = x.modInt(m);
|
|
33615
|
-
while(i < j) if(m%lowprimes[i++] == 0) return false;
|
|
33616
|
-
}
|
|
33617
|
-
return x.millerRabin(t);
|
|
33618
|
-
}
|
|
33619
|
-
|
|
33620
|
-
// (protected) true if probably prime (HAC 4.24, Miller-Rabin)
|
|
33621
|
-
function bnpMillerRabin(t) {
|
|
33622
|
-
var n1 = this.subtract(BigInteger.ONE);
|
|
33623
|
-
var k = n1.getLowestSetBit();
|
|
33624
|
-
if(k <= 0) return false;
|
|
33625
|
-
var r = n1.shiftRight(k);
|
|
33626
|
-
t = (t+1)>>1;
|
|
33627
|
-
if(t > lowprimes.length) t = lowprimes.length;
|
|
33628
|
-
var a = nbi();
|
|
33629
|
-
for(var i = 0; i < t; ++i) {
|
|
33630
|
-
//Pick bases at random, instead of starting at 2
|
|
33631
|
-
a.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);
|
|
33632
|
-
var y = a.modPow(r,this);
|
|
33633
|
-
if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
|
|
33634
|
-
var j = 1;
|
|
33635
|
-
while(j++ < k && y.compareTo(n1) != 0) {
|
|
33636
|
-
y = y.modPowInt(2,this);
|
|
33637
|
-
if(y.compareTo(BigInteger.ONE) == 0) return false;
|
|
33638
|
-
}
|
|
33639
|
-
if(y.compareTo(n1) != 0) return false;
|
|
33640
|
-
}
|
|
33641
|
-
}
|
|
33642
|
-
return true;
|
|
33643
|
-
}
|
|
33644
|
-
|
|
33645
|
-
// protected
|
|
33646
|
-
BigInteger.prototype.chunkSize = bnpChunkSize;
|
|
33647
|
-
BigInteger.prototype.toRadix = bnpToRadix;
|
|
33648
|
-
BigInteger.prototype.fromRadix = bnpFromRadix;
|
|
33649
|
-
BigInteger.prototype.fromNumber = bnpFromNumber;
|
|
33650
|
-
BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
|
|
33651
|
-
BigInteger.prototype.changeBit = bnpChangeBit;
|
|
33652
|
-
BigInteger.prototype.addTo = bnpAddTo;
|
|
33653
|
-
BigInteger.prototype.dMultiply = bnpDMultiply;
|
|
33654
|
-
BigInteger.prototype.dAddOffset = bnpDAddOffset;
|
|
33655
|
-
BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
|
|
33656
|
-
BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
|
|
33657
|
-
BigInteger.prototype.modInt = bnpModInt;
|
|
33658
|
-
BigInteger.prototype.millerRabin = bnpMillerRabin;
|
|
33659
|
-
|
|
33660
|
-
// public
|
|
33661
|
-
BigInteger.prototype.clone = bnClone;
|
|
33662
|
-
BigInteger.prototype.intValue = bnIntValue;
|
|
33663
|
-
BigInteger.prototype.byteValue = bnByteValue;
|
|
33664
|
-
BigInteger.prototype.shortValue = bnShortValue;
|
|
33665
|
-
BigInteger.prototype.signum = bnSigNum;
|
|
33666
|
-
BigInteger.prototype.toByteArray = bnToByteArray;
|
|
33667
|
-
BigInteger.prototype.equals = bnEquals;
|
|
33668
|
-
BigInteger.prototype.min = bnMin;
|
|
33669
|
-
BigInteger.prototype.max = bnMax;
|
|
33670
|
-
BigInteger.prototype.and = bnAnd;
|
|
33671
|
-
BigInteger.prototype.or = bnOr;
|
|
33672
|
-
BigInteger.prototype.xor = bnXor;
|
|
33673
|
-
BigInteger.prototype.andNot = bnAndNot;
|
|
33674
|
-
BigInteger.prototype.not = bnNot;
|
|
33675
|
-
BigInteger.prototype.shiftLeft = bnShiftLeft;
|
|
33676
|
-
BigInteger.prototype.shiftRight = bnShiftRight;
|
|
33677
|
-
BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
|
|
33678
|
-
BigInteger.prototype.bitCount = bnBitCount;
|
|
33679
|
-
BigInteger.prototype.testBit = bnTestBit;
|
|
33680
|
-
BigInteger.prototype.setBit = bnSetBit;
|
|
33681
|
-
BigInteger.prototype.clearBit = bnClearBit;
|
|
33682
|
-
BigInteger.prototype.flipBit = bnFlipBit;
|
|
33683
|
-
BigInteger.prototype.add = bnAdd;
|
|
33684
|
-
BigInteger.prototype.subtract = bnSubtract;
|
|
33685
|
-
BigInteger.prototype.multiply = bnMultiply;
|
|
33686
|
-
BigInteger.prototype.divide = bnDivide;
|
|
33687
|
-
BigInteger.prototype.remainder = bnRemainder;
|
|
33688
|
-
BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
|
|
33689
|
-
BigInteger.prototype.modPow = bnModPow;
|
|
33690
|
-
BigInteger.prototype.modInverse = bnModInverse;
|
|
33691
|
-
BigInteger.prototype.pow = bnPow;
|
|
33692
|
-
BigInteger.prototype.gcd = bnGCD;
|
|
33693
|
-
BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
|
|
33694
|
-
|
|
33695
|
-
// JSBN-specific extension
|
|
33696
|
-
BigInteger.prototype.square = bnSquare;
|
|
33697
|
-
|
|
33698
|
-
// Expose the Barrett function
|
|
33699
|
-
BigInteger.prototype.Barrett = Barrett;
|
|
33700
|
-
|
|
33701
|
-
// BigInteger interfaces not implemented in jsbn:
|
|
33702
|
-
|
|
33703
|
-
// BigInteger(int signum, byte[] magnitude)
|
|
33704
|
-
// double doubleValue()
|
|
33705
|
-
// float floatValue()
|
|
33706
|
-
// int hashCode()
|
|
33707
|
-
// long longValue()
|
|
33708
|
-
// static BigInteger valueOf(long val)
|
|
33709
|
-
|
|
33710
|
-
// Random number generator - requires a PRNG backend, e.g. prng4.js
|
|
33711
|
-
|
|
33712
|
-
// For best results, put code like
|
|
33713
|
-
// <body onClick='rng_seed_time();' onKeyPress='rng_seed_time();'>
|
|
33714
|
-
// in your main HTML document.
|
|
33715
|
-
|
|
33716
|
-
var rng_state;
|
|
33717
|
-
var rng_pool;
|
|
33718
|
-
var rng_pptr;
|
|
33719
|
-
|
|
33720
|
-
// Mix in a 32-bit integer into the pool
|
|
33721
|
-
function rng_seed_int(x) {
|
|
33722
|
-
rng_pool[rng_pptr++] ^= x & 255;
|
|
33723
|
-
rng_pool[rng_pptr++] ^= (x >> 8) & 255;
|
|
33724
|
-
rng_pool[rng_pptr++] ^= (x >> 16) & 255;
|
|
33725
|
-
rng_pool[rng_pptr++] ^= (x >> 24) & 255;
|
|
33726
|
-
if(rng_pptr >= rng_psize) rng_pptr -= rng_psize;
|
|
33727
|
-
}
|
|
33728
|
-
|
|
33729
|
-
// Mix in the current time (w/milliseconds) into the pool
|
|
33730
|
-
function rng_seed_time() {
|
|
33731
|
-
rng_seed_int(new Date().getTime());
|
|
33732
|
-
}
|
|
33733
|
-
|
|
33734
|
-
// Initialize the pool with junk if needed.
|
|
33735
|
-
if(rng_pool == null) {
|
|
33736
|
-
rng_pool = new Array();
|
|
33737
|
-
rng_pptr = 0;
|
|
33738
|
-
var t;
|
|
33739
|
-
if(typeof window !== "undefined" && window.crypto) {
|
|
33740
|
-
if (window.crypto.getRandomValues) {
|
|
33741
|
-
// Use webcrypto if available
|
|
33742
|
-
var ua = new Uint8Array(32);
|
|
33743
|
-
window.crypto.getRandomValues(ua);
|
|
33744
|
-
for(t = 0; t < 32; ++t)
|
|
33745
|
-
rng_pool[rng_pptr++] = ua[t];
|
|
33746
|
-
}
|
|
33747
|
-
else if(navigator.appName == "Netscape" && navigator.appVersion < "5") {
|
|
33748
|
-
// Extract entropy (256 bits) from NS4 RNG if available
|
|
33749
|
-
var z = window.crypto.random(32);
|
|
33750
|
-
for(t = 0; t < z.length; ++t)
|
|
33751
|
-
rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
|
|
33752
|
-
}
|
|
33753
|
-
}
|
|
33754
|
-
while(rng_pptr < rng_psize) { // extract some randomness from Math.random()
|
|
33755
|
-
t = Math.floor(65536 * Math.random());
|
|
33756
|
-
rng_pool[rng_pptr++] = t >>> 8;
|
|
33757
|
-
rng_pool[rng_pptr++] = t & 255;
|
|
33758
|
-
}
|
|
33759
|
-
rng_pptr = 0;
|
|
33760
|
-
rng_seed_time();
|
|
33761
|
-
//rng_seed_int(window.screenX);
|
|
33762
|
-
//rng_seed_int(window.screenY);
|
|
33763
|
-
}
|
|
33764
|
-
|
|
33765
|
-
function rng_get_byte() {
|
|
33766
|
-
if(rng_state == null) {
|
|
33767
|
-
rng_seed_time();
|
|
33768
|
-
rng_state = prng_newstate();
|
|
33769
|
-
rng_state.init(rng_pool);
|
|
33770
|
-
for(rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)
|
|
33771
|
-
rng_pool[rng_pptr] = 0;
|
|
33772
|
-
rng_pptr = 0;
|
|
33773
|
-
//rng_pool = null;
|
|
33774
|
-
}
|
|
33775
|
-
// TODO: allow reseeding after first request
|
|
33776
|
-
return rng_state.next();
|
|
33777
|
-
}
|
|
33778
|
-
|
|
33779
|
-
function rng_get_bytes(ba) {
|
|
33780
|
-
var i;
|
|
33781
|
-
for(i = 0; i < ba.length; ++i) ba[i] = rng_get_byte();
|
|
33782
|
-
}
|
|
33783
|
-
|
|
33784
|
-
function SecureRandom() {}
|
|
33785
|
-
|
|
33786
|
-
SecureRandom.prototype.nextBytes = rng_get_bytes;
|
|
33787
|
-
|
|
33788
|
-
// prng4.js - uses Arcfour as a PRNG
|
|
33789
|
-
|
|
33790
|
-
function Arcfour() {
|
|
33791
|
-
this.i = 0;
|
|
33792
|
-
this.j = 0;
|
|
33793
|
-
this.S = new Array();
|
|
33794
|
-
}
|
|
33795
|
-
|
|
33796
|
-
// Initialize arcfour context from key, an array of ints, each from [0..255]
|
|
33797
|
-
function ARC4init(key) {
|
|
33798
|
-
var i, j, t;
|
|
33799
|
-
for(i = 0; i < 256; ++i)
|
|
33800
|
-
this.S[i] = i;
|
|
33801
|
-
j = 0;
|
|
33802
|
-
for(i = 0; i < 256; ++i) {
|
|
33803
|
-
j = (j + this.S[i] + key[i % key.length]) & 255;
|
|
33804
|
-
t = this.S[i];
|
|
33805
|
-
this.S[i] = this.S[j];
|
|
33806
|
-
this.S[j] = t;
|
|
33807
|
-
}
|
|
33808
|
-
this.i = 0;
|
|
33809
|
-
this.j = 0;
|
|
33810
|
-
}
|
|
33811
|
-
|
|
33812
|
-
function ARC4next() {
|
|
33813
|
-
var t;
|
|
33814
|
-
this.i = (this.i + 1) & 255;
|
|
33815
|
-
this.j = (this.j + this.S[this.i]) & 255;
|
|
33816
|
-
t = this.S[this.i];
|
|
33817
|
-
this.S[this.i] = this.S[this.j];
|
|
33818
|
-
this.S[this.j] = t;
|
|
33819
|
-
return this.S[(t + this.S[this.i]) & 255];
|
|
33820
|
-
}
|
|
33821
|
-
|
|
33822
|
-
Arcfour.prototype.init = ARC4init;
|
|
33823
|
-
Arcfour.prototype.next = ARC4next;
|
|
33824
|
-
|
|
33825
|
-
// Plug in your RNG constructor here
|
|
33826
|
-
function prng_newstate() {
|
|
33827
|
-
return new Arcfour();
|
|
33828
|
-
}
|
|
33829
|
-
|
|
33830
|
-
// Pool size must be a multiple of 4 and greater than 32.
|
|
33831
|
-
// An array of bytes the size of the pool will be passed to init()
|
|
33832
|
-
var rng_psize = 256;
|
|
33833
|
-
|
|
33834
|
-
{
|
|
33835
|
-
module.exports = {
|
|
33836
|
-
default: BigInteger,
|
|
33837
|
-
BigInteger: BigInteger,
|
|
33838
|
-
SecureRandom: SecureRandom,
|
|
33839
|
-
};
|
|
33840
|
-
}
|
|
33841
|
-
|
|
33842
|
-
}).call(commonjsGlobal);
|
|
33843
|
-
} (jsbn));
|
|
33844
|
-
|
|
33845
|
-
var jsbnExports = jsbn.exports;
|
|
33846
|
-
|
|
33847
|
-
var sprintf = {};
|
|
33848
|
-
|
|
33849
|
-
/* global window, exports, define */
|
|
33850
|
-
|
|
33851
|
-
(function (exports) {
|
|
33852
|
-
!function() {
|
|
33853
|
-
|
|
33854
|
-
var re = {
|
|
33855
|
-
not_type: /[^T]/,
|
|
33856
|
-
not_primitive: /[^v]/,
|
|
33857
|
-
number: /[diefg]/,
|
|
33858
|
-
numeric_arg: /[bcdiefguxX]/,
|
|
33859
|
-
json: /[j]/,
|
|
33860
|
-
text: /^[^\x25]+/,
|
|
33861
|
-
modulo: /^\x25{2}/,
|
|
33862
|
-
placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
|
|
33863
|
-
key: /^([a-z_][a-z_\d]*)/i,
|
|
33864
|
-
key_access: /^\.([a-z_][a-z_\d]*)/i,
|
|
33865
|
-
index_access: /^\[(\d+)\]/,
|
|
33866
|
-
sign: /^[+-]/
|
|
33867
|
-
};
|
|
33868
|
-
|
|
33869
|
-
function sprintf(key) {
|
|
33870
|
-
// `arguments` is not an array, but should be fine for this call
|
|
33871
|
-
return sprintf_format(sprintf_parse(key), arguments)
|
|
33872
|
-
}
|
|
33873
|
-
|
|
33874
|
-
function vsprintf(fmt, argv) {
|
|
33875
|
-
return sprintf.apply(null, [fmt].concat(argv || []))
|
|
33876
|
-
}
|
|
33877
|
-
|
|
33878
|
-
function sprintf_format(parse_tree, argv) {
|
|
33879
|
-
var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign;
|
|
33880
|
-
for (i = 0; i < tree_length; i++) {
|
|
33881
|
-
if (typeof parse_tree[i] === 'string') {
|
|
33882
|
-
output += parse_tree[i];
|
|
33883
|
-
}
|
|
33884
|
-
else if (typeof parse_tree[i] === 'object') {
|
|
33885
|
-
ph = parse_tree[i]; // convenience purposes only
|
|
33886
|
-
if (ph.keys) { // keyword argument
|
|
33887
|
-
arg = argv[cursor];
|
|
33888
|
-
for (k = 0; k < ph.keys.length; k++) {
|
|
33889
|
-
if (arg == undefined) {
|
|
33890
|
-
throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1]))
|
|
33891
|
-
}
|
|
33892
|
-
arg = arg[ph.keys[k]];
|
|
33893
|
-
}
|
|
33894
|
-
}
|
|
33895
|
-
else if (ph.param_no) { // positional argument (explicit)
|
|
33896
|
-
arg = argv[ph.param_no];
|
|
33897
|
-
}
|
|
33898
|
-
else { // positional argument (implicit)
|
|
33899
|
-
arg = argv[cursor++];
|
|
33900
|
-
}
|
|
33901
|
-
|
|
33902
|
-
if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
|
|
33903
|
-
arg = arg();
|
|
33904
|
-
}
|
|
33905
|
-
|
|
33906
|
-
if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) {
|
|
33907
|
-
throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg))
|
|
33908
|
-
}
|
|
33909
|
-
|
|
33910
|
-
if (re.number.test(ph.type)) {
|
|
33911
|
-
is_positive = arg >= 0;
|
|
33912
|
-
}
|
|
33913
|
-
|
|
33914
|
-
switch (ph.type) {
|
|
33915
|
-
case 'b':
|
|
33916
|
-
arg = parseInt(arg, 10).toString(2);
|
|
33917
|
-
break
|
|
33918
|
-
case 'c':
|
|
33919
|
-
arg = String.fromCharCode(parseInt(arg, 10));
|
|
33920
|
-
break
|
|
33921
|
-
case 'd':
|
|
33922
|
-
case 'i':
|
|
33923
|
-
arg = parseInt(arg, 10);
|
|
33924
|
-
break
|
|
33925
|
-
case 'j':
|
|
33926
|
-
arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0);
|
|
33927
|
-
break
|
|
33928
|
-
case 'e':
|
|
33929
|
-
arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential();
|
|
33930
|
-
break
|
|
33931
|
-
case 'f':
|
|
33932
|
-
arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg);
|
|
33933
|
-
break
|
|
33934
|
-
case 'g':
|
|
33935
|
-
arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg);
|
|
33936
|
-
break
|
|
33937
|
-
case 'o':
|
|
33938
|
-
arg = (parseInt(arg, 10) >>> 0).toString(8);
|
|
33939
|
-
break
|
|
33940
|
-
case 's':
|
|
33941
|
-
arg = String(arg);
|
|
33942
|
-
arg = (ph.precision ? arg.substring(0, ph.precision) : arg);
|
|
33943
|
-
break
|
|
33944
|
-
case 't':
|
|
33945
|
-
arg = String(!!arg);
|
|
33946
|
-
arg = (ph.precision ? arg.substring(0, ph.precision) : arg);
|
|
33947
|
-
break
|
|
33948
|
-
case 'T':
|
|
33949
|
-
arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase();
|
|
33950
|
-
arg = (ph.precision ? arg.substring(0, ph.precision) : arg);
|
|
33951
|
-
break
|
|
33952
|
-
case 'u':
|
|
33953
|
-
arg = parseInt(arg, 10) >>> 0;
|
|
33954
|
-
break
|
|
33955
|
-
case 'v':
|
|
33956
|
-
arg = arg.valueOf();
|
|
33957
|
-
arg = (ph.precision ? arg.substring(0, ph.precision) : arg);
|
|
33958
|
-
break
|
|
33959
|
-
case 'x':
|
|
33960
|
-
arg = (parseInt(arg, 10) >>> 0).toString(16);
|
|
33961
|
-
break
|
|
33962
|
-
case 'X':
|
|
33963
|
-
arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase();
|
|
33964
|
-
break
|
|
33965
|
-
}
|
|
33966
|
-
if (re.json.test(ph.type)) {
|
|
33967
|
-
output += arg;
|
|
33968
|
-
}
|
|
33969
|
-
else {
|
|
33970
|
-
if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
|
|
33971
|
-
sign = is_positive ? '+' : '-';
|
|
33972
|
-
arg = arg.toString().replace(re.sign, '');
|
|
33973
|
-
}
|
|
33974
|
-
else {
|
|
33975
|
-
sign = '';
|
|
33976
|
-
}
|
|
33977
|
-
pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' ';
|
|
33978
|
-
pad_length = ph.width - (sign + arg).length;
|
|
33979
|
-
pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : '';
|
|
33980
|
-
output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg);
|
|
33981
|
-
}
|
|
33982
|
-
}
|
|
33983
|
-
}
|
|
33984
|
-
return output
|
|
33985
|
-
}
|
|
33986
|
-
|
|
33987
|
-
var sprintf_cache = Object.create(null);
|
|
33988
|
-
|
|
33989
|
-
function sprintf_parse(fmt) {
|
|
33990
|
-
if (sprintf_cache[fmt]) {
|
|
33991
|
-
return sprintf_cache[fmt]
|
|
33992
|
-
}
|
|
33993
|
-
|
|
33994
|
-
var _fmt = fmt, match, parse_tree = [], arg_names = 0;
|
|
33995
|
-
while (_fmt) {
|
|
33996
|
-
if ((match = re.text.exec(_fmt)) !== null) {
|
|
33997
|
-
parse_tree.push(match[0]);
|
|
33998
|
-
}
|
|
33999
|
-
else if ((match = re.modulo.exec(_fmt)) !== null) {
|
|
34000
|
-
parse_tree.push('%');
|
|
34001
|
-
}
|
|
34002
|
-
else if ((match = re.placeholder.exec(_fmt)) !== null) {
|
|
34003
|
-
if (match[2]) {
|
|
34004
|
-
arg_names |= 1;
|
|
34005
|
-
var field_list = [], replacement_field = match[2], field_match = [];
|
|
34006
|
-
if ((field_match = re.key.exec(replacement_field)) !== null) {
|
|
34007
|
-
field_list.push(field_match[1]);
|
|
34008
|
-
while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
|
|
34009
|
-
if ((field_match = re.key_access.exec(replacement_field)) !== null) {
|
|
34010
|
-
field_list.push(field_match[1]);
|
|
34011
|
-
}
|
|
34012
|
-
else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
|
|
34013
|
-
field_list.push(field_match[1]);
|
|
34014
|
-
}
|
|
34015
|
-
else {
|
|
34016
|
-
throw new SyntaxError('[sprintf] failed to parse named argument key')
|
|
34017
|
-
}
|
|
34018
|
-
}
|
|
34019
|
-
}
|
|
34020
|
-
else {
|
|
34021
|
-
throw new SyntaxError('[sprintf] failed to parse named argument key')
|
|
34022
|
-
}
|
|
34023
|
-
match[2] = field_list;
|
|
34024
|
-
}
|
|
34025
|
-
else {
|
|
34026
|
-
arg_names |= 2;
|
|
34027
|
-
}
|
|
34028
|
-
if (arg_names === 3) {
|
|
34029
|
-
throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported')
|
|
34030
|
-
}
|
|
34031
|
-
|
|
34032
|
-
parse_tree.push(
|
|
34033
|
-
{
|
|
34034
|
-
placeholder: match[0],
|
|
34035
|
-
param_no: match[1],
|
|
34036
|
-
keys: match[2],
|
|
34037
|
-
sign: match[3],
|
|
34038
|
-
pad_char: match[4],
|
|
34039
|
-
align: match[5],
|
|
34040
|
-
width: match[6],
|
|
34041
|
-
precision: match[7],
|
|
34042
|
-
type: match[8]
|
|
34043
|
-
}
|
|
34044
|
-
);
|
|
34045
|
-
}
|
|
34046
|
-
else {
|
|
34047
|
-
throw new SyntaxError('[sprintf] unexpected placeholder')
|
|
34048
|
-
}
|
|
34049
|
-
_fmt = _fmt.substring(match[0].length);
|
|
34050
|
-
}
|
|
34051
|
-
return sprintf_cache[fmt] = parse_tree
|
|
34052
|
-
}
|
|
34053
|
-
|
|
34054
|
-
/**
|
|
34055
|
-
* export to either browser or node.js
|
|
34056
|
-
*/
|
|
34057
|
-
/* eslint-disable quote-props */
|
|
34058
|
-
{
|
|
34059
|
-
exports['sprintf'] = sprintf;
|
|
34060
|
-
exports['vsprintf'] = vsprintf;
|
|
34061
|
-
}
|
|
34062
|
-
if (typeof window !== 'undefined') {
|
|
34063
|
-
window['sprintf'] = sprintf;
|
|
34064
|
-
window['vsprintf'] = vsprintf;
|
|
34065
|
-
}
|
|
34066
|
-
/* eslint-enable quote-props */
|
|
34067
|
-
}(); // eslint-disable-line
|
|
34068
|
-
} (sprintf));
|
|
34069
|
-
|
|
34070
32502
|
/* eslint-disable no-param-reassign */
|
|
34071
32503
|
var __createBinding$5 = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
34072
32504
|
if (k2 === undefined) k2 = k;
|
|
@@ -34096,8 +32528,6 @@ ipv4.Address4 = void 0;
|
|
|
34096
32528
|
const common$2 = __importStar$5(common$3);
|
|
34097
32529
|
const constants$1 = __importStar$5(constants$2);
|
|
34098
32530
|
const address_error_1$1 = addressError;
|
|
34099
|
-
const jsbn_1$1 = jsbnExports;
|
|
34100
|
-
const sprintf_js_1$3 = sprintf;
|
|
34101
32531
|
/**
|
|
34102
32532
|
* Represents an IPv4 address
|
|
34103
32533
|
* @class Address4
|
|
@@ -34218,7 +32648,7 @@ class Address4 {
|
|
|
34218
32648
|
* @returns {String}
|
|
34219
32649
|
*/
|
|
34220
32650
|
toHex() {
|
|
34221
|
-
return this.parsedAddress.map((part) =>
|
|
32651
|
+
return this.parsedAddress.map((part) => common$2.stringToPaddedHex(part)).join(':');
|
|
34222
32652
|
}
|
|
34223
32653
|
/**
|
|
34224
32654
|
* Converts an IPv4 address object to an array of bytes
|
|
@@ -34239,28 +32669,27 @@ class Address4 {
|
|
|
34239
32669
|
const output = [];
|
|
34240
32670
|
let i;
|
|
34241
32671
|
for (i = 0; i < constants$1.GROUPS; i += 2) {
|
|
34242
|
-
|
|
34243
|
-
output.push((0, sprintf_js_1$3.sprintf)('%x', parseInt(hex, 16)));
|
|
32672
|
+
output.push(`${common$2.stringToPaddedHex(this.parsedAddress[i])}${common$2.stringToPaddedHex(this.parsedAddress[i + 1])}`);
|
|
34244
32673
|
}
|
|
34245
32674
|
return output.join(':');
|
|
34246
32675
|
}
|
|
34247
32676
|
/**
|
|
34248
|
-
* Returns the address as a
|
|
32677
|
+
* Returns the address as a `bigint`
|
|
34249
32678
|
* @memberof Address4
|
|
34250
32679
|
* @instance
|
|
34251
|
-
* @returns {
|
|
32680
|
+
* @returns {bigint}
|
|
34252
32681
|
*/
|
|
34253
|
-
|
|
34254
|
-
return
|
|
32682
|
+
bigInt() {
|
|
32683
|
+
return BigInt(`0x${this.parsedAddress.map((n) => common$2.stringToPaddedHex(n)).join('')}`);
|
|
34255
32684
|
}
|
|
34256
32685
|
/**
|
|
34257
32686
|
* Helper function getting start address.
|
|
34258
32687
|
* @memberof Address4
|
|
34259
32688
|
* @instance
|
|
34260
|
-
* @returns {
|
|
32689
|
+
* @returns {bigint}
|
|
34261
32690
|
*/
|
|
34262
32691
|
_startAddress() {
|
|
34263
|
-
return
|
|
32692
|
+
return BigInt(`0b${this.mask() + '0'.repeat(constants$1.BITS - this.subnetMask)}`);
|
|
34264
32693
|
}
|
|
34265
32694
|
/**
|
|
34266
32695
|
* The first address in the range given by this address' subnet.
|
|
@@ -34270,7 +32699,7 @@ class Address4 {
|
|
|
34270
32699
|
* @returns {Address4}
|
|
34271
32700
|
*/
|
|
34272
32701
|
startAddress() {
|
|
34273
|
-
return Address4.
|
|
32702
|
+
return Address4.fromBigInt(this._startAddress());
|
|
34274
32703
|
}
|
|
34275
32704
|
/**
|
|
34276
32705
|
* The first host address in the range given by this address's subnet ie
|
|
@@ -34280,17 +32709,17 @@ class Address4 {
|
|
|
34280
32709
|
* @returns {Address4}
|
|
34281
32710
|
*/
|
|
34282
32711
|
startAddressExclusive() {
|
|
34283
|
-
const adjust =
|
|
34284
|
-
return Address4.
|
|
32712
|
+
const adjust = BigInt('1');
|
|
32713
|
+
return Address4.fromBigInt(this._startAddress() + adjust);
|
|
34285
32714
|
}
|
|
34286
32715
|
/**
|
|
34287
32716
|
* Helper function getting end address.
|
|
34288
32717
|
* @memberof Address4
|
|
34289
32718
|
* @instance
|
|
34290
|
-
* @returns {
|
|
32719
|
+
* @returns {bigint}
|
|
34291
32720
|
*/
|
|
34292
32721
|
_endAddress() {
|
|
34293
|
-
return
|
|
32722
|
+
return BigInt(`0b${this.mask() + '1'.repeat(constants$1.BITS - this.subnetMask)}`);
|
|
34294
32723
|
}
|
|
34295
32724
|
/**
|
|
34296
32725
|
* The last address in the range given by this address' subnet
|
|
@@ -34300,7 +32729,7 @@ class Address4 {
|
|
|
34300
32729
|
* @returns {Address4}
|
|
34301
32730
|
*/
|
|
34302
32731
|
endAddress() {
|
|
34303
|
-
return Address4.
|
|
32732
|
+
return Address4.fromBigInt(this._endAddress());
|
|
34304
32733
|
}
|
|
34305
32734
|
/**
|
|
34306
32735
|
* The last host address in the range given by this address's subnet ie
|
|
@@ -34310,18 +32739,18 @@ class Address4 {
|
|
|
34310
32739
|
* @returns {Address4}
|
|
34311
32740
|
*/
|
|
34312
32741
|
endAddressExclusive() {
|
|
34313
|
-
const adjust =
|
|
34314
|
-
return Address4.
|
|
32742
|
+
const adjust = BigInt('1');
|
|
32743
|
+
return Address4.fromBigInt(this._endAddress() - adjust);
|
|
34315
32744
|
}
|
|
34316
32745
|
/**
|
|
34317
|
-
* Converts a
|
|
32746
|
+
* Converts a BigInt to a v4 address object
|
|
34318
32747
|
* @memberof Address4
|
|
34319
32748
|
* @static
|
|
34320
|
-
* @param {
|
|
32749
|
+
* @param {bigint} bigInt - a BigInt to convert
|
|
34321
32750
|
* @returns {Address4}
|
|
34322
32751
|
*/
|
|
34323
|
-
static
|
|
34324
|
-
return Address4.
|
|
32752
|
+
static fromBigInt(bigInt) {
|
|
32753
|
+
return Address4.fromHex(bigInt.toString(16));
|
|
34325
32754
|
}
|
|
34326
32755
|
/**
|
|
34327
32756
|
* Returns the first n bits of the address, defaulting to the
|
|
@@ -34361,7 +32790,7 @@ class Address4 {
|
|
|
34361
32790
|
if (options.omitSuffix) {
|
|
34362
32791
|
return reversed;
|
|
34363
32792
|
}
|
|
34364
|
-
return
|
|
32793
|
+
return `${reversed}.in-addr.arpa.`;
|
|
34365
32794
|
}
|
|
34366
32795
|
/**
|
|
34367
32796
|
* Returns true if the given address is a multicast address
|
|
@@ -34379,7 +32808,7 @@ class Address4 {
|
|
|
34379
32808
|
* @returns {string}
|
|
34380
32809
|
*/
|
|
34381
32810
|
binaryZeroPad() {
|
|
34382
|
-
return this.
|
|
32811
|
+
return this.bigInt().toString(2).padStart(constants$1.BITS, '0');
|
|
34383
32812
|
}
|
|
34384
32813
|
/**
|
|
34385
32814
|
* Groups an IPv4 address for inclusion at the end of an IPv6 address
|
|
@@ -34387,7 +32816,11 @@ class Address4 {
|
|
|
34387
32816
|
*/
|
|
34388
32817
|
groupForV6() {
|
|
34389
32818
|
const segments = this.parsedAddress;
|
|
34390
|
-
return this.address.replace(constants$1.RE_ADDRESS,
|
|
32819
|
+
return this.address.replace(constants$1.RE_ADDRESS, `<span class="hover-group group-v4 group-6">${segments
|
|
32820
|
+
.slice(0, 2)
|
|
32821
|
+
.join('.')}</span>.<span class="hover-group group-v4 group-7">${segments
|
|
32822
|
+
.slice(2, 4)
|
|
32823
|
+
.join('.')}</span>`);
|
|
34391
32824
|
}
|
|
34392
32825
|
}
|
|
34393
32826
|
ipv4.Address4 = Address4;
|
|
@@ -34468,32 +32901,31 @@ constants.RE_SUBNET_STRING = /\/\d{1,3}(?=%|$)/;
|
|
|
34468
32901
|
* @static
|
|
34469
32902
|
*/
|
|
34470
32903
|
constants.RE_ZONE_STRING = /%.*$/;
|
|
34471
|
-
constants.RE_URL =
|
|
34472
|
-
constants.RE_URL_WITH_PORT =
|
|
32904
|
+
constants.RE_URL = /^\[{0,1}([0-9a-f:]+)\]{0,1}/;
|
|
32905
|
+
constants.RE_URL_WITH_PORT = /\[([0-9a-f:]+)\]:([0-9]{1,5})/;
|
|
34473
32906
|
|
|
34474
32907
|
var helpers$1 = {};
|
|
34475
32908
|
|
|
34476
32909
|
Object.defineProperty(helpers$1, "__esModule", { value: true });
|
|
34477
|
-
helpers$1.
|
|
34478
|
-
|
|
32910
|
+
helpers$1.spanAllZeroes = spanAllZeroes;
|
|
32911
|
+
helpers$1.spanAll = spanAll;
|
|
32912
|
+
helpers$1.spanLeadingZeroes = spanLeadingZeroes;
|
|
32913
|
+
helpers$1.simpleGroup = simpleGroup;
|
|
34479
32914
|
/**
|
|
34480
32915
|
* @returns {String} the string with all zeroes contained in a <span>
|
|
34481
32916
|
*/
|
|
34482
32917
|
function spanAllZeroes(s) {
|
|
34483
32918
|
return s.replace(/(0+)/g, '<span class="zero">$1</span>');
|
|
34484
32919
|
}
|
|
34485
|
-
helpers$1.spanAllZeroes = spanAllZeroes;
|
|
34486
32920
|
/**
|
|
34487
32921
|
* @returns {String} the string with each character contained in a <span>
|
|
34488
32922
|
*/
|
|
34489
32923
|
function spanAll(s, offset = 0) {
|
|
34490
32924
|
const letters = s.split('');
|
|
34491
32925
|
return letters
|
|
34492
|
-
.map((n, i) =>
|
|
34493
|
-
)
|
|
32926
|
+
.map((n, i) => `<span class="digit value-${n} position-${i + offset}">${spanAllZeroes(n)}</span>`)
|
|
34494
32927
|
.join('');
|
|
34495
32928
|
}
|
|
34496
|
-
helpers$1.spanAll = spanAll;
|
|
34497
32929
|
function spanLeadingZeroesSimple(group) {
|
|
34498
32930
|
return group.replace(/^(0+)/, '<span class="zero">$1</span>');
|
|
34499
32931
|
}
|
|
@@ -34504,7 +32936,6 @@ function spanLeadingZeroes(address) {
|
|
|
34504
32936
|
const groups = address.split(':');
|
|
34505
32937
|
return groups.map((g) => spanLeadingZeroesSimple(g)).join(':');
|
|
34506
32938
|
}
|
|
34507
|
-
helpers$1.spanLeadingZeroes = spanLeadingZeroes;
|
|
34508
32939
|
/**
|
|
34509
32940
|
* Groups an address
|
|
34510
32941
|
* @returns {String} a grouped address
|
|
@@ -34515,10 +32946,9 @@ function simpleGroup(addressString, offset = 0) {
|
|
|
34515
32946
|
if (/group-v4/.test(g)) {
|
|
34516
32947
|
return g;
|
|
34517
32948
|
}
|
|
34518
|
-
return
|
|
32949
|
+
return `<span class="hover-group group-${i + offset}">${spanLeadingZeroesSimple(g)}</span>`;
|
|
34519
32950
|
});
|
|
34520
32951
|
}
|
|
34521
|
-
helpers$1.simpleGroup = simpleGroup;
|
|
34522
32952
|
|
|
34523
32953
|
var regularExpressions = {};
|
|
34524
32954
|
|
|
@@ -34546,20 +32976,21 @@ var __importStar$4 = (commonjsGlobal && commonjsGlobal.__importStar) || function
|
|
|
34546
32976
|
return result;
|
|
34547
32977
|
};
|
|
34548
32978
|
Object.defineProperty(regularExpressions, "__esModule", { value: true });
|
|
34549
|
-
regularExpressions.
|
|
32979
|
+
regularExpressions.ADDRESS_BOUNDARY = void 0;
|
|
32980
|
+
regularExpressions.groupPossibilities = groupPossibilities;
|
|
32981
|
+
regularExpressions.padGroup = padGroup;
|
|
32982
|
+
regularExpressions.simpleRegularExpression = simpleRegularExpression;
|
|
32983
|
+
regularExpressions.possibleElisions = possibleElisions;
|
|
34550
32984
|
const v6 = __importStar$4(constants);
|
|
34551
|
-
const sprintf_js_1$1 = sprintf;
|
|
34552
32985
|
function groupPossibilities(possibilities) {
|
|
34553
|
-
return (
|
|
32986
|
+
return `(${possibilities.join('|')})`;
|
|
34554
32987
|
}
|
|
34555
|
-
regularExpressions.groupPossibilities = groupPossibilities;
|
|
34556
32988
|
function padGroup(group) {
|
|
34557
32989
|
if (group.length < 4) {
|
|
34558
|
-
return
|
|
32990
|
+
return `0{0,${4 - group.length}}${group}`;
|
|
34559
32991
|
}
|
|
34560
32992
|
return group;
|
|
34561
32993
|
}
|
|
34562
|
-
regularExpressions.padGroup = padGroup;
|
|
34563
32994
|
regularExpressions.ADDRESS_BOUNDARY = '[^A-Fa-f0-9:]';
|
|
34564
32995
|
function simpleRegularExpression(groups) {
|
|
34565
32996
|
const zeroIndexes = [];
|
|
@@ -34584,7 +33015,6 @@ function simpleRegularExpression(groups) {
|
|
|
34584
33015
|
possibilities.push(groups.map(padGroup).join(':'));
|
|
34585
33016
|
return groupPossibilities(possibilities);
|
|
34586
33017
|
}
|
|
34587
|
-
regularExpressions.simpleRegularExpression = simpleRegularExpression;
|
|
34588
33018
|
function possibleElisions(elidedGroups, moreLeft, moreRight) {
|
|
34589
33019
|
const left = moreLeft ? '' : ':';
|
|
34590
33020
|
const right = moreRight ? '' : ':';
|
|
@@ -34602,20 +33032,19 @@ function possibleElisions(elidedGroups, moreLeft, moreRight) {
|
|
|
34602
33032
|
possibilities.push(':');
|
|
34603
33033
|
}
|
|
34604
33034
|
// 4. elision from the left side
|
|
34605
|
-
possibilities.push((
|
|
33035
|
+
possibilities.push(`${left}(:0{1,4}){1,${elidedGroups - 1}}`);
|
|
34606
33036
|
// 5. elision from the right side
|
|
34607
|
-
possibilities.push((0
|
|
33037
|
+
possibilities.push(`(0{1,4}:){1,${elidedGroups - 1}}${right}`);
|
|
34608
33038
|
// 6. no elision
|
|
34609
|
-
possibilities.push((0
|
|
33039
|
+
possibilities.push(`(0{1,4}:){${elidedGroups - 1}}0{1,4}`);
|
|
34610
33040
|
// 7. elision (including sloppy elision) from the middle
|
|
34611
33041
|
for (let groups = 1; groups < elidedGroups - 1; groups++) {
|
|
34612
33042
|
for (let position = 1; position < elidedGroups - groups; position++) {
|
|
34613
|
-
possibilities.push((0
|
|
33043
|
+
possibilities.push(`(0{1,4}:){${position}}:(0{1,4}:){${elidedGroups - position - groups - 1}}0{1,4}`);
|
|
34614
33044
|
}
|
|
34615
33045
|
}
|
|
34616
33046
|
return groupPossibilities(possibilities);
|
|
34617
33047
|
}
|
|
34618
|
-
regularExpressions.possibleElisions = possibleElisions;
|
|
34619
33048
|
|
|
34620
33049
|
/* eslint-disable prefer-destructuring */
|
|
34621
33050
|
/* eslint-disable no-param-reassign */
|
|
@@ -34651,8 +33080,7 @@ const helpers = __importStar$3(helpers$1);
|
|
|
34651
33080
|
const ipv4_1 = ipv4;
|
|
34652
33081
|
const regular_expressions_1 = regularExpressions;
|
|
34653
33082
|
const address_error_1 = addressError;
|
|
34654
|
-
const
|
|
34655
|
-
const sprintf_js_1 = sprintf;
|
|
33083
|
+
const common_1 = common$3;
|
|
34656
33084
|
function assert(condition) {
|
|
34657
33085
|
if (!condition) {
|
|
34658
33086
|
throw new Error('Assertion failed.');
|
|
@@ -34688,7 +33116,7 @@ function compact(address, slice) {
|
|
|
34688
33116
|
return s1.concat(['compact']).concat(s2);
|
|
34689
33117
|
}
|
|
34690
33118
|
function paddedHex(octet) {
|
|
34691
|
-
return (
|
|
33119
|
+
return parseInt(octet, 16).toString(16).padStart(4, '0');
|
|
34692
33120
|
}
|
|
34693
33121
|
function unsignByte(b) {
|
|
34694
33122
|
// eslint-disable-next-line no-bitwise
|
|
@@ -34766,18 +33194,18 @@ class Address6 {
|
|
|
34766
33194
|
}
|
|
34767
33195
|
}
|
|
34768
33196
|
/**
|
|
34769
|
-
* Convert a
|
|
33197
|
+
* Convert a BigInt to a v6 address object
|
|
34770
33198
|
* @memberof Address6
|
|
34771
33199
|
* @static
|
|
34772
|
-
* @param {
|
|
33200
|
+
* @param {bigint} bigInt - a BigInt to convert
|
|
34773
33201
|
* @returns {Address6}
|
|
34774
33202
|
* @example
|
|
34775
|
-
* var
|
|
34776
|
-
* var address = Address6.
|
|
33203
|
+
* var bigInt = BigInt('1000000000000');
|
|
33204
|
+
* var address = Address6.fromBigInt(bigInt);
|
|
34777
33205
|
* address.correctForm(); // '::e8:d4a5:1000'
|
|
34778
33206
|
*/
|
|
34779
|
-
static
|
|
34780
|
-
const hex =
|
|
33207
|
+
static fromBigInt(bigInt) {
|
|
33208
|
+
const hex = bigInt.toString(16).padStart(32, '0');
|
|
34781
33209
|
const groups = [];
|
|
34782
33210
|
let i;
|
|
34783
33211
|
for (i = 0; i < constants6.GROUPS; i++) {
|
|
@@ -34897,7 +33325,7 @@ class Address6 {
|
|
|
34897
33325
|
* @returns {String} the Microsoft UNC transcription of the address
|
|
34898
33326
|
*/
|
|
34899
33327
|
microsoftTranscription() {
|
|
34900
|
-
return
|
|
33328
|
+
return `${this.correctForm().replace(/:/g, '-')}.ipv6-literal.net`;
|
|
34901
33329
|
}
|
|
34902
33330
|
/**
|
|
34903
33331
|
* Return the first n bits of the address, defaulting to the subnet mask
|
|
@@ -34913,7 +33341,7 @@ class Address6 {
|
|
|
34913
33341
|
* Return the number of possible subnets of a given size in the address
|
|
34914
33342
|
* @memberof Address6
|
|
34915
33343
|
* @instance
|
|
34916
|
-
* @param {number} [
|
|
33344
|
+
* @param {number} [subnetSize=128] - the subnet size
|
|
34917
33345
|
* @returns {String}
|
|
34918
33346
|
*/
|
|
34919
33347
|
// TODO: probably useful to have a numeric version of this too
|
|
@@ -34924,16 +33352,16 @@ class Address6 {
|
|
|
34924
33352
|
if (subnetPowers < 0) {
|
|
34925
33353
|
return '0';
|
|
34926
33354
|
}
|
|
34927
|
-
return addCommas(
|
|
33355
|
+
return addCommas((BigInt('2') ** BigInt(subnetPowers)).toString(10));
|
|
34928
33356
|
}
|
|
34929
33357
|
/**
|
|
34930
33358
|
* Helper function getting start address.
|
|
34931
33359
|
* @memberof Address6
|
|
34932
33360
|
* @instance
|
|
34933
|
-
* @returns {
|
|
33361
|
+
* @returns {bigint}
|
|
34934
33362
|
*/
|
|
34935
33363
|
_startAddress() {
|
|
34936
|
-
return
|
|
33364
|
+
return BigInt(`0b${this.mask() + '0'.repeat(constants6.BITS - this.subnetMask)}`);
|
|
34937
33365
|
}
|
|
34938
33366
|
/**
|
|
34939
33367
|
* The first address in the range given by this address' subnet
|
|
@@ -34943,7 +33371,7 @@ class Address6 {
|
|
|
34943
33371
|
* @returns {Address6}
|
|
34944
33372
|
*/
|
|
34945
33373
|
startAddress() {
|
|
34946
|
-
return Address6.
|
|
33374
|
+
return Address6.fromBigInt(this._startAddress());
|
|
34947
33375
|
}
|
|
34948
33376
|
/**
|
|
34949
33377
|
* The first host address in the range given by this address's subnet ie
|
|
@@ -34953,17 +33381,17 @@ class Address6 {
|
|
|
34953
33381
|
* @returns {Address6}
|
|
34954
33382
|
*/
|
|
34955
33383
|
startAddressExclusive() {
|
|
34956
|
-
const adjust =
|
|
34957
|
-
return Address6.
|
|
33384
|
+
const adjust = BigInt('1');
|
|
33385
|
+
return Address6.fromBigInt(this._startAddress() + adjust);
|
|
34958
33386
|
}
|
|
34959
33387
|
/**
|
|
34960
33388
|
* Helper function getting end address.
|
|
34961
33389
|
* @memberof Address6
|
|
34962
33390
|
* @instance
|
|
34963
|
-
* @returns {
|
|
33391
|
+
* @returns {bigint}
|
|
34964
33392
|
*/
|
|
34965
33393
|
_endAddress() {
|
|
34966
|
-
return
|
|
33394
|
+
return BigInt(`0b${this.mask() + '1'.repeat(constants6.BITS - this.subnetMask)}`);
|
|
34967
33395
|
}
|
|
34968
33396
|
/**
|
|
34969
33397
|
* The last address in the range given by this address' subnet
|
|
@@ -34973,7 +33401,7 @@ class Address6 {
|
|
|
34973
33401
|
* @returns {Address6}
|
|
34974
33402
|
*/
|
|
34975
33403
|
endAddress() {
|
|
34976
|
-
return Address6.
|
|
33404
|
+
return Address6.fromBigInt(this._endAddress());
|
|
34977
33405
|
}
|
|
34978
33406
|
/**
|
|
34979
33407
|
* The last host address in the range given by this address's subnet ie
|
|
@@ -34983,8 +33411,8 @@ class Address6 {
|
|
|
34983
33411
|
* @returns {Address6}
|
|
34984
33412
|
*/
|
|
34985
33413
|
endAddressExclusive() {
|
|
34986
|
-
const adjust =
|
|
34987
|
-
return Address6.
|
|
33414
|
+
const adjust = BigInt('1');
|
|
33415
|
+
return Address6.fromBigInt(this._endAddress() - adjust);
|
|
34988
33416
|
}
|
|
34989
33417
|
/**
|
|
34990
33418
|
* Return the scope of the address
|
|
@@ -34993,7 +33421,7 @@ class Address6 {
|
|
|
34993
33421
|
* @returns {String}
|
|
34994
33422
|
*/
|
|
34995
33423
|
getScope() {
|
|
34996
|
-
let scope = constants6.SCOPES[this.getBits(12, 16).
|
|
33424
|
+
let scope = constants6.SCOPES[parseInt(this.getBits(12, 16).toString(10), 10)];
|
|
34997
33425
|
if (this.getType() === 'Global unicast' && scope !== 'Link local') {
|
|
34998
33426
|
scope = 'Global';
|
|
34999
33427
|
}
|
|
@@ -35014,13 +33442,13 @@ class Address6 {
|
|
|
35014
33442
|
return 'Global unicast';
|
|
35015
33443
|
}
|
|
35016
33444
|
/**
|
|
35017
|
-
* Return the bits in the given range as a
|
|
33445
|
+
* Return the bits in the given range as a BigInt
|
|
35018
33446
|
* @memberof Address6
|
|
35019
33447
|
* @instance
|
|
35020
|
-
* @returns {
|
|
33448
|
+
* @returns {bigint}
|
|
35021
33449
|
*/
|
|
35022
33450
|
getBits(start, end) {
|
|
35023
|
-
return
|
|
33451
|
+
return BigInt(`0b${this.getBitsBase2(start, end)}`);
|
|
35024
33452
|
}
|
|
35025
33453
|
/**
|
|
35026
33454
|
* Return the bits in the given range as a base-2 string
|
|
@@ -35078,7 +33506,7 @@ class Address6 {
|
|
|
35078
33506
|
if (options.omitSuffix) {
|
|
35079
33507
|
return reversed;
|
|
35080
33508
|
}
|
|
35081
|
-
return
|
|
33509
|
+
return `${reversed}.ip6.arpa.`;
|
|
35082
33510
|
}
|
|
35083
33511
|
if (options.omitSuffix) {
|
|
35084
33512
|
return '';
|
|
@@ -35127,7 +33555,7 @@ class Address6 {
|
|
|
35127
33555
|
}
|
|
35128
33556
|
let correct = groups.join(':');
|
|
35129
33557
|
correct = correct.replace(/^compact$/, '::');
|
|
35130
|
-
correct = correct.replace(
|
|
33558
|
+
correct = correct.replace(/(^compact)|(compact$)/, ':');
|
|
35131
33559
|
correct = correct.replace(/compact/, '');
|
|
35132
33560
|
return correct;
|
|
35133
33561
|
}
|
|
@@ -35143,7 +33571,7 @@ class Address6 {
|
|
|
35143
33571
|
* // 0000000000000000000000000000000000000000000000000001000000010001'
|
|
35144
33572
|
*/
|
|
35145
33573
|
binaryZeroPad() {
|
|
35146
|
-
return this.
|
|
33574
|
+
return this.bigInt().toString(2).padStart(constants6.BITS, '0');
|
|
35147
33575
|
}
|
|
35148
33576
|
// TODO: Improve the semantics of this helper function
|
|
35149
33577
|
parse4in6(address) {
|
|
@@ -35169,11 +33597,11 @@ class Address6 {
|
|
|
35169
33597
|
address = this.parse4in6(address);
|
|
35170
33598
|
const badCharacters = address.match(constants6.RE_BAD_CHARACTERS);
|
|
35171
33599
|
if (badCharacters) {
|
|
35172
|
-
throw new address_error_1.AddressError(
|
|
33600
|
+
throw new address_error_1.AddressError(`Bad character${badCharacters.length > 1 ? 's' : ''} detected in address: ${badCharacters.join('')}`, address.replace(constants6.RE_BAD_CHARACTERS, '<span class="parse-error">$1</span>'));
|
|
35173
33601
|
}
|
|
35174
33602
|
const badAddress = address.match(constants6.RE_BAD_ADDRESS);
|
|
35175
33603
|
if (badAddress) {
|
|
35176
|
-
throw new address_error_1.AddressError(
|
|
33604
|
+
throw new address_error_1.AddressError(`Address failed regex: ${badAddress.join('')}`, address.replace(constants6.RE_BAD_ADDRESS, '<span class="parse-error">$1</span>'));
|
|
35177
33605
|
}
|
|
35178
33606
|
let groups = [];
|
|
35179
33607
|
const halves = address.split('::');
|
|
@@ -35206,7 +33634,7 @@ class Address6 {
|
|
|
35206
33634
|
else {
|
|
35207
33635
|
throw new address_error_1.AddressError('Too many :: groups found');
|
|
35208
33636
|
}
|
|
35209
|
-
groups = groups.map((group) =>
|
|
33637
|
+
groups = groups.map((group) => parseInt(group, 16).toString(16));
|
|
35210
33638
|
if (groups.length !== this.groups) {
|
|
35211
33639
|
throw new address_error_1.AddressError('Incorrect number of groups found');
|
|
35212
33640
|
}
|
|
@@ -35228,16 +33656,16 @@ class Address6 {
|
|
|
35228
33656
|
* @returns {String}
|
|
35229
33657
|
*/
|
|
35230
33658
|
decimal() {
|
|
35231
|
-
return this.parsedAddress.map((n) => (
|
|
33659
|
+
return this.parsedAddress.map((n) => parseInt(n, 16).toString(10).padStart(5, '0')).join(':');
|
|
35232
33660
|
}
|
|
35233
33661
|
/**
|
|
35234
|
-
* Return the address as a
|
|
33662
|
+
* Return the address as a BigInt
|
|
35235
33663
|
* @memberof Address6
|
|
35236
33664
|
* @instance
|
|
35237
|
-
* @returns {
|
|
33665
|
+
* @returns {bigint}
|
|
35238
33666
|
*/
|
|
35239
|
-
|
|
35240
|
-
return
|
|
33667
|
+
bigInt() {
|
|
33668
|
+
return BigInt(`0x${this.parsedAddress.map(paddedHex).join('')}`);
|
|
35241
33669
|
}
|
|
35242
33670
|
/**
|
|
35243
33671
|
* Return the last two groups of this address as an IPv4 address string
|
|
@@ -35250,7 +33678,7 @@ class Address6 {
|
|
|
35250
33678
|
*/
|
|
35251
33679
|
to4() {
|
|
35252
33680
|
const binary = this.binaryZeroPad().split('');
|
|
35253
|
-
return ipv4_1.Address4.fromHex(
|
|
33681
|
+
return ipv4_1.Address4.fromHex(BigInt(`0b${binary.slice(96, 128).join('')}`).toString(16));
|
|
35254
33682
|
}
|
|
35255
33683
|
/**
|
|
35256
33684
|
* Return the v4-in-v6 form of the address
|
|
@@ -35297,18 +33725,21 @@ class Address6 {
|
|
|
35297
33725
|
public IPv4 address of the NAT with all bits inverted.
|
|
35298
33726
|
*/
|
|
35299
33727
|
const prefix = this.getBitsBase16(0, 32);
|
|
35300
|
-
const
|
|
33728
|
+
const bitsForUdpPort = this.getBits(80, 96);
|
|
33729
|
+
// eslint-disable-next-line no-bitwise
|
|
33730
|
+
const udpPort = (bitsForUdpPort ^ BigInt('0xffff')).toString();
|
|
35301
33731
|
const server4 = ipv4_1.Address4.fromHex(this.getBitsBase16(32, 64));
|
|
35302
|
-
const
|
|
35303
|
-
|
|
33732
|
+
const bitsForClient4 = this.getBits(96, 128);
|
|
33733
|
+
// eslint-disable-next-line no-bitwise
|
|
33734
|
+
const client4 = ipv4_1.Address4.fromHex((bitsForClient4 ^ BigInt('0xffffffff')).toString(16));
|
|
35304
33735
|
const flagsBase2 = this.getBitsBase2(64, 80);
|
|
35305
|
-
const coneNat =
|
|
35306
|
-
const reserved =
|
|
35307
|
-
const groupIndividual =
|
|
35308
|
-
const universalLocal =
|
|
35309
|
-
const nonce =
|
|
33736
|
+
const coneNat = (0, common_1.testBit)(flagsBase2, 15);
|
|
33737
|
+
const reserved = (0, common_1.testBit)(flagsBase2, 14);
|
|
33738
|
+
const groupIndividual = (0, common_1.testBit)(flagsBase2, 8);
|
|
33739
|
+
const universalLocal = (0, common_1.testBit)(flagsBase2, 9);
|
|
33740
|
+
const nonce = BigInt(`0b${flagsBase2.slice(2, 6) + flagsBase2.slice(8, 16)}`).toString(10);
|
|
35310
33741
|
return {
|
|
35311
|
-
prefix:
|
|
33742
|
+
prefix: `${prefix.slice(0, 4)}:${prefix.slice(4, 8)}`,
|
|
35312
33743
|
server4: server4.address,
|
|
35313
33744
|
client4: client4.address,
|
|
35314
33745
|
flags: flagsBase2,
|
|
@@ -35336,7 +33767,7 @@ class Address6 {
|
|
|
35336
33767
|
const prefix = this.getBitsBase16(0, 16);
|
|
35337
33768
|
const gateway = ipv4_1.Address4.fromHex(this.getBitsBase16(16, 48));
|
|
35338
33769
|
return {
|
|
35339
|
-
prefix:
|
|
33770
|
+
prefix: prefix.slice(0, 4),
|
|
35340
33771
|
gateway: gateway.address,
|
|
35341
33772
|
};
|
|
35342
33773
|
}
|
|
@@ -35366,12 +33797,14 @@ class Address6 {
|
|
|
35366
33797
|
* @returns {Array}
|
|
35367
33798
|
*/
|
|
35368
33799
|
toByteArray() {
|
|
35369
|
-
const
|
|
35370
|
-
|
|
35371
|
-
|
|
35372
|
-
|
|
33800
|
+
const valueWithoutPadding = this.bigInt().toString(16);
|
|
33801
|
+
const leadingPad = '0'.repeat(valueWithoutPadding.length % 2);
|
|
33802
|
+
const value = `${leadingPad}${valueWithoutPadding}`;
|
|
33803
|
+
const bytes = [];
|
|
33804
|
+
for (let i = 0, length = value.length; i < length; i += 2) {
|
|
33805
|
+
bytes.push(parseInt(value.substring(i, i + 2), 16));
|
|
35373
33806
|
}
|
|
35374
|
-
return
|
|
33807
|
+
return bytes;
|
|
35375
33808
|
}
|
|
35376
33809
|
/**
|
|
35377
33810
|
* Return an unsigned byte array
|
|
@@ -35398,14 +33831,14 @@ class Address6 {
|
|
|
35398
33831
|
* @returns {Address6}
|
|
35399
33832
|
*/
|
|
35400
33833
|
static fromUnsignedByteArray(bytes) {
|
|
35401
|
-
const BYTE_MAX =
|
|
35402
|
-
let result =
|
|
35403
|
-
let multiplier =
|
|
33834
|
+
const BYTE_MAX = BigInt('256');
|
|
33835
|
+
let result = BigInt('0');
|
|
33836
|
+
let multiplier = BigInt('1');
|
|
35404
33837
|
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
35405
|
-
result
|
|
35406
|
-
multiplier
|
|
33838
|
+
result += multiplier * BigInt(bytes[i].toString(10));
|
|
33839
|
+
multiplier *= BYTE_MAX;
|
|
35407
33840
|
}
|
|
35408
|
-
return Address6.
|
|
33841
|
+
return Address6.fromBigInt(result);
|
|
35409
33842
|
}
|
|
35410
33843
|
/**
|
|
35411
33844
|
* Returns true if the address is in the canonical form, false otherwise
|
|
@@ -35485,9 +33918,9 @@ class Address6 {
|
|
|
35485
33918
|
optionalPort = '';
|
|
35486
33919
|
}
|
|
35487
33920
|
else {
|
|
35488
|
-
optionalPort =
|
|
33921
|
+
optionalPort = `:${optionalPort}`;
|
|
35489
33922
|
}
|
|
35490
|
-
return
|
|
33923
|
+
return `http://[${this.correctForm()}]${optionalPort}/`;
|
|
35491
33924
|
}
|
|
35492
33925
|
/**
|
|
35493
33926
|
* @returns {String} a link suitable for conveying the address via a URL hash
|
|
@@ -35509,10 +33942,11 @@ class Address6 {
|
|
|
35509
33942
|
if (options.v4) {
|
|
35510
33943
|
formFunction = this.to4in6;
|
|
35511
33944
|
}
|
|
33945
|
+
const form = formFunction.call(this);
|
|
35512
33946
|
if (options.className) {
|
|
35513
|
-
return
|
|
33947
|
+
return `<a href="${options.prefix}${form}" class="${options.className}">${form}</a>`;
|
|
35514
33948
|
}
|
|
35515
|
-
return
|
|
33949
|
+
return `<a href="${options.prefix}${form}">${form}</a>`;
|
|
35516
33950
|
}
|
|
35517
33951
|
/**
|
|
35518
33952
|
* Groups an address
|
|
@@ -35536,9 +33970,9 @@ class Address6 {
|
|
|
35536
33970
|
}
|
|
35537
33971
|
const classes = ['hover-group'];
|
|
35538
33972
|
for (let i = this.elisionBegin; i < this.elisionBegin + this.elidedGroups; i++) {
|
|
35539
|
-
classes.push(
|
|
33973
|
+
classes.push(`group-${i}`);
|
|
35540
33974
|
}
|
|
35541
|
-
output.push(
|
|
33975
|
+
output.push(`<span class="${classes.join(' ')}"></span>`);
|
|
35542
33976
|
if (right.length) {
|
|
35543
33977
|
output.push(...helpers.simpleGroup(right, this.elisionEnd));
|
|
35544
33978
|
}
|
|
@@ -35640,11 +34074,11 @@ ipv6.Address6 = Address6;
|
|
|
35640
34074
|
};
|
|
35641
34075
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35642
34076
|
exports.v6 = exports.AddressError = exports.Address6 = exports.Address4 = void 0;
|
|
35643
|
-
|
|
34077
|
+
var ipv4_1 = ipv4;
|
|
35644
34078
|
Object.defineProperty(exports, "Address4", { enumerable: true, get: function () { return ipv4_1.Address4; } });
|
|
35645
|
-
|
|
34079
|
+
var ipv6_1 = ipv6;
|
|
35646
34080
|
Object.defineProperty(exports, "Address6", { enumerable: true, get: function () { return ipv6_1.Address6; } });
|
|
35647
|
-
|
|
34081
|
+
var address_error_1 = addressError;
|
|
35648
34082
|
Object.defineProperty(exports, "AddressError", { enumerable: true, get: function () { return address_error_1.AddressError; } });
|
|
35649
34083
|
const helpers = __importStar(helpers$1);
|
|
35650
34084
|
exports.v6 = { helpers };
|
|
@@ -35756,6 +34190,7 @@ function validateCustomProxyAuth(proxy, options) {
|
|
|
35756
34190
|
function isValidSocksRemoteHost(remoteHost) {
|
|
35757
34191
|
return (remoteHost &&
|
|
35758
34192
|
typeof remoteHost.host === 'string' &&
|
|
34193
|
+
Buffer.byteLength(remoteHost.host) < 256 &&
|
|
35759
34194
|
typeof remoteHost.port === 'number' &&
|
|
35760
34195
|
remoteHost.port >= 0 &&
|
|
35761
34196
|
remoteHost.port <= 65535);
|
|
@@ -35782,7 +34217,7 @@ function isValidTimeoutValue(value) {
|
|
|
35782
34217
|
function ipv4ToInt32(ip) {
|
|
35783
34218
|
const address = new ip_address_1.Address4(ip);
|
|
35784
34219
|
// Convert the IPv4 address parts to an integer
|
|
35785
|
-
return address.toArray().reduce((acc, part) => (acc << 8) + part, 0);
|
|
34220
|
+
return address.toArray().reduce((acc, part) => (acc << 8) + part, 0) >>> 0;
|
|
35786
34221
|
}
|
|
35787
34222
|
helpers$2.ipv4ToInt32 = ipv4ToInt32;
|
|
35788
34223
|
function int32ToIpv4(int32) {
|