Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

jsbn.js 32KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. // Copyright (c) 2005 Tom Wu
  2. // All Rights Reserved.
  3. // See "LICENSE" for details.
  4. // Basic JavaScript BN library - subset useful for RSA encryption.
  5. // Bits per digit
  6. var dbits;
  7. // JavaScript engine analysis
  8. var canary = 0xdeadbeefcafe;
  9. var j_lm = ((canary&0xffffff)==0xefcafe);
  10. // (public) Constructor
  11. function BigInteger(a,b,c) {
  12. if(a != null)
  13. if("number" == typeof a) this.fromNumber(a,b,c);
  14. else if(b == null && "string" != typeof a) this.fromString(a,256);
  15. else this.fromString(a,b);
  16. }
  17. // return new, unset BigInteger
  18. function nbi() { return new BigInteger(null); }
  19. // am: Compute w_j += (x*this_i), propagate carries,
  20. // c is initial carry, returns final carry.
  21. // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
  22. // We need to select the fastest one that works in this environment.
  23. // Set max digit bits to 28 since some
  24. // browsers slow down when dealing with 32-bit numbers.
  25. function am3(i,x,w,j,c,n) {
  26. var xl = x&0x3fff, xh = x>>14;
  27. while(--n >= 0) {
  28. var l = this[i]&0x3fff;
  29. var h = this[i++]>>14;
  30. var m = xh*l+h*xl;
  31. l = xl*l+((m&0x3fff)<<14)+w[j]+c;
  32. c = (l>>28)+(m>>14)+xh*h;
  33. w[j++] = l&0xfffffff;
  34. }
  35. return c;
  36. }
  37. BigInteger.prototype.am = am3;
  38. dbits = 28;
  39. BigInteger.prototype.DB = dbits;
  40. BigInteger.prototype.DM = ((1<<dbits)-1);
  41. BigInteger.prototype.DV = (1<<dbits);
  42. var BI_FP = 52;
  43. BigInteger.prototype.FV = Math.pow(2,BI_FP);
  44. BigInteger.prototype.F1 = BI_FP-dbits;
  45. BigInteger.prototype.F2 = 2*dbits-BI_FP;
  46. // Digit conversions
  47. var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
  48. var BI_RC = new Array();
  49. var rr,vv;
  50. rr = "0".charCodeAt(0);
  51. for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
  52. rr = "a".charCodeAt(0);
  53. for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
  54. rr = "A".charCodeAt(0);
  55. for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
  56. function int2char(n) { return BI_RM.charAt(n); }
  57. function intAt(s,i) {
  58. var c = BI_RC[s.charCodeAt(i)];
  59. return (c==null)?-1:c;
  60. }
  61. // (protected) copy this to r
  62. function bnpCopyTo(r) {
  63. for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
  64. r.t = this.t;
  65. r.s = this.s;
  66. }
  67. // (protected) set from integer value x, -DV <= x < DV
  68. function bnpFromInt(x) {
  69. this.t = 1;
  70. this.s = (x<0)?-1:0;
  71. if(x > 0) this[0] = x;
  72. else if(x < -1) this[0] = x+this.DV;
  73. else this.t = 0;
  74. }
  75. // return bigint initialized to value
  76. function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
  77. // (protected) set from string and radix
  78. function bnpFromString(s,b) {
  79. var k;
  80. if(b == 16) k = 4;
  81. else if(b == 8) k = 3;
  82. else if(b == 256) k = 8; // byte array
  83. else if(b == 2) k = 1;
  84. else if(b == 32) k = 5;
  85. else if(b == 4) k = 2;
  86. else { this.fromRadix(s,b); return; }
  87. this.t = 0;
  88. this.s = 0;
  89. var i = s.length, mi = false, sh = 0;
  90. while(--i >= 0) {
  91. var x = (k==8)?s[i]&0xff:intAt(s,i);
  92. if(x < 0) {
  93. if(s.charAt(i) == "-") mi = true;
  94. continue;
  95. }
  96. mi = false;
  97. if(sh == 0)
  98. this[this.t++] = x;
  99. else if(sh+k > this.DB) {
  100. this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh;
  101. this[this.t++] = (x>>(this.DB-sh));
  102. }
  103. else
  104. this[this.t-1] |= x<<sh;
  105. sh += k;
  106. if(sh >= this.DB) sh -= this.DB;
  107. }
  108. if(k == 8 && (s[0]&0x80) != 0) {
  109. this.s = -1;
  110. if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh;
  111. }
  112. this.clamp();
  113. if(mi) BigInteger.ZERO.subTo(this,this);
  114. }
  115. // (protected) clamp off excess high words
  116. function bnpClamp() {
  117. var c = this.s&this.DM;
  118. while(this.t > 0 && this[this.t-1] == c) --this.t;
  119. }
  120. // (public) return string representation in given radix
  121. function bnToString(b) {
  122. if(this.s < 0) return "-"+this.negate().toString(b);
  123. var k;
  124. if(b == 16) k = 4;
  125. else if(b == 8) k = 3;
  126. else if(b == 2) k = 1;
  127. else if(b == 32) k = 5;
  128. else if(b == 4) k = 2;
  129. else return this.toRadix(b);
  130. var km = (1<<k)-1, d, m = false, r = "", i = this.t;
  131. var p = this.DB-(i*this.DB)%k;
  132. if(i-- > 0) {
  133. if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
  134. while(i >= 0) {
  135. if(p < k) {
  136. d = (this[i]&((1<<p)-1))<<(k-p);
  137. d |= this[--i]>>(p+=this.DB-k);
  138. }
  139. else {
  140. d = (this[i]>>(p-=k))&km;
  141. if(p <= 0) { p += this.DB; --i; }
  142. }
  143. if(d > 0) m = true;
  144. if(m) r += int2char(d);
  145. }
  146. }
  147. return m?r:"0";
  148. }
  149. // (public) -this
  150. function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }
  151. // (public) |this|
  152. function bnAbs() { return (this.s<0)?this.negate():this; }
  153. // (public) return + if this > a, - if this < a, 0 if equal
  154. function bnCompareTo(a) {
  155. var r = this.s-a.s;
  156. if(r != 0) return r;
  157. var i = this.t;
  158. r = i-a.t;
  159. if(r != 0) return (this.s<0)?-r:r;
  160. while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
  161. return 0;
  162. }
  163. // returns bit length of the integer x
  164. function nbits(x) {
  165. var r = 1, t;
  166. if((t=x>>>16) != 0) { x = t; r += 16; }
  167. if((t=x>>8) != 0) { x = t; r += 8; }
  168. if((t=x>>4) != 0) { x = t; r += 4; }
  169. if((t=x>>2) != 0) { x = t; r += 2; }
  170. if((t=x>>1) != 0) { x = t; r += 1; }
  171. return r;
  172. }
  173. // (public) return the number of bits in "this"
  174. function bnBitLength() {
  175. if(this.t <= 0) return 0;
  176. return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));
  177. }
  178. // (protected) r = this << n*DB
  179. function bnpDLShiftTo(n,r) {
  180. var i;
  181. for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
  182. for(i = n-1; i >= 0; --i) r[i] = 0;
  183. r.t = this.t+n;
  184. r.s = this.s;
  185. }
  186. // (protected) r = this >> n*DB
  187. function bnpDRShiftTo(n,r) {
  188. for(var i = n; i < this.t; ++i) r[i-n] = this[i];
  189. r.t = Math.max(this.t-n,0);
  190. r.s = this.s;
  191. }
  192. // (protected) r = this << n
  193. function bnpLShiftTo(n,r) {
  194. var bs = n%this.DB;
  195. var cbs = this.DB-bs;
  196. var bm = (1<<cbs)-1;
  197. var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i;
  198. for(i = this.t-1; i >= 0; --i) {
  199. r[i+ds+1] = (this[i]>>cbs)|c;
  200. c = (this[i]&bm)<<bs;
  201. }
  202. for(i = ds-1; i >= 0; --i) r[i] = 0;
  203. r[ds] = c;
  204. r.t = this.t+ds+1;
  205. r.s = this.s;
  206. r.clamp();
  207. }
  208. // (protected) r = this >> n
  209. function bnpRShiftTo(n,r) {
  210. r.s = this.s;
  211. var ds = Math.floor(n/this.DB);
  212. if(ds >= this.t) { r.t = 0; return; }
  213. var bs = n%this.DB;
  214. var cbs = this.DB-bs;
  215. var bm = (1<<bs)-1;
  216. r[0] = this[ds]>>bs;
  217. for(var i = ds+1; i < this.t; ++i) {
  218. r[i-ds-1] |= (this[i]&bm)<<cbs;
  219. r[i-ds] = this[i]>>bs;
  220. }
  221. if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
  222. r.t = this.t-ds;
  223. r.clamp();
  224. }
  225. // (protected) r = this - a
  226. function bnpSubTo(a,r) {
  227. var i = 0, c = 0, m = Math.min(a.t,this.t);
  228. while(i < m) {
  229. c += this[i]-a[i];
  230. r[i++] = c&this.DM;
  231. c >>= this.DB;
  232. }
  233. if(a.t < this.t) {
  234. c -= a.s;
  235. while(i < this.t) {
  236. c += this[i];
  237. r[i++] = c&this.DM;
  238. c >>= this.DB;
  239. }
  240. c += this.s;
  241. }
  242. else {
  243. c += this.s;
  244. while(i < a.t) {
  245. c -= a[i];
  246. r[i++] = c&this.DM;
  247. c >>= this.DB;
  248. }
  249. c -= a.s;
  250. }
  251. r.s = (c<0)?-1:0;
  252. if(c < -1) r[i++] = this.DV+c;
  253. else if(c > 0) r[i++] = c;
  254. r.t = i;
  255. r.clamp();
  256. }
  257. // (protected) r = this * a, r != this,a (HAC 14.12)
  258. // "this" should be the larger one if appropriate.
  259. function bnpMultiplyTo(a,r) {
  260. var x = this.abs(), y = a.abs();
  261. var i = x.t;
  262. r.t = i+y.t;
  263. while(--i >= 0) r[i] = 0;
  264. for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
  265. r.s = 0;
  266. r.clamp();
  267. if(this.s != a.s) BigInteger.ZERO.subTo(r,r);
  268. }
  269. // (protected) r = this^2, r != this (HAC 14.16)
  270. function bnpSquareTo(r) {
  271. var x = this.abs();
  272. var i = r.t = 2*x.t;
  273. while(--i >= 0) r[i] = 0;
  274. for(i = 0; i < x.t-1; ++i) {
  275. var c = x.am(i,x[i],r,2*i,0,1);
  276. if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) {
  277. r[i+x.t] -= x.DV;
  278. r[i+x.t+1] = 1;
  279. }
  280. }
  281. if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
  282. r.s = 0;
  283. r.clamp();
  284. }
  285. // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
  286. // r != q, this != m. q or r may be null.
  287. function bnpDivRemTo(m,q,r) {
  288. var pm = m.abs();
  289. if(pm.t <= 0) return;
  290. var pt = this.abs();
  291. if(pt.t < pm.t) {
  292. if(q != null) q.fromInt(0);
  293. if(r != null) this.copyTo(r);
  294. return;
  295. }
  296. if(r == null) r = nbi();
  297. var y = nbi(), ts = this.s, ms = m.s;
  298. var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus
  299. if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); }
  300. else { pm.copyTo(y); pt.copyTo(r); }
  301. var ys = y.t;
  302. var y0 = y[ys-1];
  303. if(y0 == 0) return;
  304. var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0);
  305. var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2;
  306. var i = r.t, j = i-ys, t = (q==null)?nbi():q;
  307. y.dlShiftTo(j,t);
  308. if(r.compareTo(t) >= 0) {
  309. r[r.t++] = 1;
  310. r.subTo(t,r);
  311. }
  312. BigInteger.ONE.dlShiftTo(ys,t);
  313. t.subTo(y,y); // "negative" y so we can replace sub with am later
  314. while(y.t < ys) y[y.t++] = 0;
  315. while(--j >= 0) {
  316. // Estimate quotient digit
  317. var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);
  318. if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
  319. y.dlShiftTo(j,t);
  320. r.subTo(t,r);
  321. while(r[i] < --qd) r.subTo(t,r);
  322. }
  323. }
  324. if(q != null) {
  325. r.drShiftTo(ys,q);
  326. if(ts != ms) BigInteger.ZERO.subTo(q,q);
  327. }
  328. r.t = ys;
  329. r.clamp();
  330. if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder
  331. if(ts < 0) BigInteger.ZERO.subTo(r,r);
  332. }
  333. // (public) this mod a
  334. function bnMod(a) {
  335. var r = nbi();
  336. this.abs().divRemTo(a,null,r);
  337. if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r);
  338. return r;
  339. }
  340. // Modular reduction using "classic" algorithm
  341. function Classic(m) { this.m = m; }
  342. function cConvert(x) {
  343. if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
  344. else return x;
  345. }
  346. function cRevert(x) { return x; }
  347. function cReduce(x) { x.divRemTo(this.m,null,x); }
  348. function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
  349. function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
  350. Classic.prototype.convert = cConvert;
  351. Classic.prototype.revert = cRevert;
  352. Classic.prototype.reduce = cReduce;
  353. Classic.prototype.mulTo = cMulTo;
  354. Classic.prototype.sqrTo = cSqrTo;
  355. // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
  356. // justification:
  357. // xy == 1 (mod m)
  358. // xy = 1+km
  359. // xy(2-xy) = (1+km)(1-km)
  360. // x[y(2-xy)] = 1-k^2m^2
  361. // x[y(2-xy)] == 1 (mod m^2)
  362. // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
  363. // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
  364. // JS multiply "overflows" differently from C/C++, so care is needed here.
  365. function bnpInvDigit() {
  366. if(this.t < 1) return 0;
  367. var x = this[0];
  368. if((x&1) == 0) return 0;
  369. var y = x&3; // y == 1/x mod 2^2
  370. y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
  371. y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
  372. y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
  373. // last step - calculate inverse mod DV directly;
  374. // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
  375. y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits
  376. // we really want the negative inverse, and -DV < y < DV
  377. return (y>0)?this.DV-y:-y;
  378. }
  379. // Montgomery reduction
  380. function Montgomery(m) {
  381. this.m = m;
  382. this.mp = m.invDigit();
  383. this.mpl = this.mp&0x7fff;
  384. this.mph = this.mp>>15;
  385. this.um = (1<<(m.DB-15))-1;
  386. this.mt2 = 2*m.t;
  387. }
  388. // xR mod m
  389. function montConvert(x) {
  390. var r = nbi();
  391. x.abs().dlShiftTo(this.m.t,r);
  392. r.divRemTo(this.m,null,r);
  393. if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r);
  394. return r;
  395. }
  396. // x/R mod m
  397. function montRevert(x) {
  398. var r = nbi();
  399. x.copyTo(r);
  400. this.reduce(r);
  401. return r;
  402. }
  403. // x = x/R mod m (HAC 14.32)
  404. function montReduce(x) {
  405. while(x.t <= this.mt2) // pad x so am has enough room later
  406. x[x.t++] = 0;
  407. for(var i = 0; i < this.m.t; ++i) {
  408. // faster way of calculating u0 = x[i]*mp mod DV
  409. var j = x[i]&0x7fff;
  410. var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;
  411. // use am to combine the multiply-shift-add into one call
  412. j = i+this.m.t;
  413. x[j] += this.m.am(0,u0,x,i,0,this.m.t);
  414. // propagate carry
  415. while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; }
  416. }
  417. x.clamp();
  418. x.drShiftTo(this.m.t,x);
  419. if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
  420. }
  421. // r = "x^2/R mod m"; x != r
  422. function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
  423. // r = "xy/R mod m"; x,y != r
  424. function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
  425. Montgomery.prototype.convert = montConvert;
  426. Montgomery.prototype.revert = montRevert;
  427. Montgomery.prototype.reduce = montReduce;
  428. Montgomery.prototype.mulTo = montMulTo;
  429. Montgomery.prototype.sqrTo = montSqrTo;
  430. // (protected) true iff this is even
  431. function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
  432. // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
  433. function bnpExp(e,z) {
  434. if(e > 0xffffffff || e < 1) return BigInteger.ONE;
  435. var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
  436. g.copyTo(r);
  437. while(--i >= 0) {
  438. z.sqrTo(r,r2);
  439. if((e&(1<<i)) > 0) z.mulTo(r2,g,r);
  440. else { var t = r; r = r2; r2 = t; }
  441. }
  442. return z.revert(r);
  443. }
  444. // (public) this^e % m, 0 <= e < 2^32
  445. function bnModPowInt(e,m) {
  446. var z;
  447. if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
  448. return this.exp(e,z);
  449. }
  450. // protected
  451. BigInteger.prototype.copyTo = bnpCopyTo;
  452. BigInteger.prototype.fromInt = bnpFromInt;
  453. BigInteger.prototype.fromString = bnpFromString;
  454. BigInteger.prototype.clamp = bnpClamp;
  455. BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
  456. BigInteger.prototype.drShiftTo = bnpDRShiftTo;
  457. BigInteger.prototype.lShiftTo = bnpLShiftTo;
  458. BigInteger.prototype.rShiftTo = bnpRShiftTo;
  459. BigInteger.prototype.subTo = bnpSubTo;
  460. BigInteger.prototype.multiplyTo = bnpMultiplyTo;
  461. BigInteger.prototype.squareTo = bnpSquareTo;
  462. BigInteger.prototype.divRemTo = bnpDivRemTo;
  463. BigInteger.prototype.invDigit = bnpInvDigit;
  464. BigInteger.prototype.isEven = bnpIsEven;
  465. BigInteger.prototype.exp = bnpExp;
  466. // public
  467. BigInteger.prototype.toString = bnToString;
  468. BigInteger.prototype.negate = bnNegate;
  469. BigInteger.prototype.abs = bnAbs;
  470. BigInteger.prototype.compareTo = bnCompareTo;
  471. BigInteger.prototype.bitLength = bnBitLength;
  472. BigInteger.prototype.mod = bnMod;
  473. BigInteger.prototype.modPowInt = bnModPowInt;
  474. // "constants"
  475. BigInteger.ZERO = nbv(0);
  476. BigInteger.ONE = nbv(1);
  477. // Copyright (c) 2005-2009 Tom Wu
  478. // All Rights Reserved.
  479. // See "LICENSE" for details.
  480. // Extended JavaScript BN functions, required for RSA private ops.
  481. // Version 1.1: new BigInteger("0", 10) returns "proper" zero
  482. // Version 1.2: square() API, isProbablePrime fix
  483. // (public)
  484. function bnClone() { var r = nbi(); this.copyTo(r); return r; }
  485. // (public) return value as integer
  486. function bnIntValue() {
  487. if(this.s < 0) {
  488. if(this.t == 1) return this[0]-this.DV;
  489. else if(this.t == 0) return -1;
  490. }
  491. else if(this.t == 1) return this[0];
  492. else if(this.t == 0) return 0;
  493. // assumes 16 < DB < 32
  494. return ((this[1]&((1<<(32-this.DB))-1))<<this.DB)|this[0];
  495. }
  496. // (public) return value as byte
  497. function bnByteValue() { return (this.t==0)?this.s:(this[0]<<24)>>24; }
  498. // (public) return value as short (assumes DB>=16)
  499. function bnShortValue() { return (this.t==0)?this.s:(this[0]<<16)>>16; }
  500. // (protected) return x s.t. r^x < DV
  501. function bnpChunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); }
  502. // (public) 0 if this == 0, 1 if this > 0
  503. function bnSigNum() {
  504. if(this.s < 0) return -1;
  505. else if(this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0;
  506. else return 1;
  507. }
  508. // (protected) convert to radix string
  509. function bnpToRadix(b) {
  510. if(b == null) b = 10;
  511. if(this.signum() == 0 || b < 2 || b > 36) return "0";
  512. var cs = this.chunkSize(b);
  513. var a = Math.pow(b,cs);
  514. var d = nbv(a), y = nbi(), z = nbi(), r = "";
  515. this.divRemTo(d,y,z);
  516. while(y.signum() > 0) {
  517. r = (a+z.intValue()).toString(b).substr(1) + r;
  518. y.divRemTo(d,y,z);
  519. }
  520. return z.intValue().toString(b) + r;
  521. }
  522. // (protected) convert from radix string
  523. function bnpFromRadix(s,b) {
  524. this.fromInt(0);
  525. if(b == null) b = 10;
  526. var cs = this.chunkSize(b);
  527. var d = Math.pow(b,cs), mi = false, j = 0, w = 0;
  528. for(var i = 0; i < s.length; ++i) {
  529. var x = intAt(s,i);
  530. if(x < 0) {
  531. if(s.charAt(i) == "-" && this.signum() == 0) mi = true;
  532. continue;
  533. }
  534. w = b*w+x;
  535. if(++j >= cs) {
  536. this.dMultiply(d);
  537. this.dAddOffset(w,0);
  538. j = 0;
  539. w = 0;
  540. }
  541. }
  542. if(j > 0) {
  543. this.dMultiply(Math.pow(b,j));
  544. this.dAddOffset(w,0);
  545. }
  546. if(mi) BigInteger.ZERO.subTo(this,this);
  547. }
  548. // (protected) alternate constructor
  549. function bnpFromNumber(a,b,c) {
  550. if("number" == typeof b) {
  551. // new BigInteger(int,int,RNG)
  552. if(a < 2) this.fromInt(1);
  553. else {
  554. this.fromNumber(a,c);
  555. if(!this.testBit(a-1)) // force MSB set
  556. this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this);
  557. if(this.isEven()) this.dAddOffset(1,0); // force odd
  558. while(!this.isProbablePrime(b)) {
  559. this.dAddOffset(2,0);
  560. if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this);
  561. }
  562. }
  563. }
  564. else {
  565. // new BigInteger(int,RNG)
  566. var x = new Array(), t = a&7;
  567. x.length = (a>>3)+1;
  568. b.nextBytes(x);
  569. if(t > 0) x[0] &= ((1<<t)-1); else x[0] = 0;
  570. this.fromString(x,256);
  571. }
  572. }
  573. // (public) convert to bigendian byte array
  574. function bnToByteArray() {
  575. var i = this.t, r = new Array();
  576. r[0] = this.s;
  577. var p = this.DB-(i*this.DB)%8, d, k = 0;
  578. if(i-- > 0) {
  579. if(p < this.DB && (d = this[i]>>p) != (this.s&this.DM)>>p)
  580. r[k++] = d|(this.s<<(this.DB-p));
  581. while(i >= 0) {
  582. if(p < 8) {
  583. d = (this[i]&((1<<p)-1))<<(8-p);
  584. d |= this[--i]>>(p+=this.DB-8);
  585. }
  586. else {
  587. d = (this[i]>>(p-=8))&0xff;
  588. if(p <= 0) { p += this.DB; --i; }
  589. }
  590. if((d&0x80) != 0) d |= -256;
  591. if(k == 0 && (this.s&0x80) != (d&0x80)) ++k;
  592. if(k > 0 || d != this.s) r[k++] = d;
  593. }
  594. }
  595. return r;
  596. }
  597. function bnEquals(a) { return(this.compareTo(a)==0); }
  598. function bnMin(a) { return(this.compareTo(a)<0)?this:a; }
  599. function bnMax(a) { return(this.compareTo(a)>0)?this:a; }
  600. // (protected) r = this op a (bitwise)
  601. function bnpBitwiseTo(a,op,r) {
  602. var i, f, m = Math.min(a.t,this.t);
  603. for(i = 0; i < m; ++i) r[i] = op(this[i],a[i]);
  604. if(a.t < this.t) {
  605. f = a.s&this.DM;
  606. for(i = m; i < this.t; ++i) r[i] = op(this[i],f);
  607. r.t = this.t;
  608. }
  609. else {
  610. f = this.s&this.DM;
  611. for(i = m; i < a.t; ++i) r[i] = op(f,a[i]);
  612. r.t = a.t;
  613. }
  614. r.s = op(this.s,a.s);
  615. r.clamp();
  616. }
  617. // (public) this & a
  618. function op_and(x,y) { return x&y; }
  619. function bnAnd(a) { var r = nbi(); this.bitwiseTo(a,op_and,r); return r; }
  620. // (public) this | a
  621. function op_or(x,y) { return x|y; }
  622. function bnOr(a) { var r = nbi(); this.bitwiseTo(a,op_or,r); return r; }
  623. // (public) this ^ a
  624. function op_xor(x,y) { return x^y; }
  625. function bnXor(a) { var r = nbi(); this.bitwiseTo(a,op_xor,r); return r; }
  626. // (public) this & ~a
  627. function op_andnot(x,y) { return x&~y; }
  628. function bnAndNot(a) { var r = nbi(); this.bitwiseTo(a,op_andnot,r); return r; }
  629. // (public) ~this
  630. function bnNot() {
  631. var r = nbi();
  632. for(var i = 0; i < this.t; ++i) r[i] = this.DM&~this[i];
  633. r.t = this.t;
  634. r.s = ~this.s;
  635. return r;
  636. }
  637. // (public) this << n
  638. function bnShiftLeft(n) {
  639. var r = nbi();
  640. if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r);
  641. return r;
  642. }
  643. // (public) this >> n
  644. function bnShiftRight(n) {
  645. var r = nbi();
  646. if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r);
  647. return r;
  648. }
  649. // return index of lowest 1-bit in x, x < 2^31
  650. function lbit(x) {
  651. if(x == 0) return -1;
  652. var r = 0;
  653. if((x&0xffff) == 0) { x >>= 16; r += 16; }
  654. if((x&0xff) == 0) { x >>= 8; r += 8; }
  655. if((x&0xf) == 0) { x >>= 4; r += 4; }
  656. if((x&3) == 0) { x >>= 2; r += 2; }
  657. if((x&1) == 0) ++r;
  658. return r;
  659. }
  660. // (public) returns index of lowest 1-bit (or -1 if none)
  661. function bnGetLowestSetBit() {
  662. for(var i = 0; i < this.t; ++i)
  663. if(this[i] != 0) return i*this.DB+lbit(this[i]);
  664. if(this.s < 0) return this.t*this.DB;
  665. return -1;
  666. }
  667. // return number of 1 bits in x
  668. function cbit(x) {
  669. var r = 0;
  670. while(x != 0) { x &= x-1; ++r; }
  671. return r;
  672. }
  673. // (public) return number of set bits
  674. function bnBitCount() {
  675. var r = 0, x = this.s&this.DM;
  676. for(var i = 0; i < this.t; ++i) r += cbit(this[i]^x);
  677. return r;
  678. }
  679. // (public) true iff nth bit is set
  680. function bnTestBit(n) {
  681. var j = Math.floor(n/this.DB);
  682. if(j >= this.t) return(this.s!=0);
  683. return((this[j]&(1<<(n%this.DB)))!=0);
  684. }
  685. // (protected) this op (1<<n)
  686. function bnpChangeBit(n,op) {
  687. var r = BigInteger.ONE.shiftLeft(n);
  688. this.bitwiseTo(r,op,r);
  689. return r;
  690. }
  691. // (public) this | (1<<n)
  692. function bnSetBit(n) { return this.changeBit(n,op_or); }
  693. // (public) this & ~(1<<n)
  694. function bnClearBit(n) { return this.changeBit(n,op_andnot); }
  695. // (public) this ^ (1<<n)
  696. function bnFlipBit(n) { return this.changeBit(n,op_xor); }
  697. // (protected) r = this + a
  698. function bnpAddTo(a,r) {
  699. var i = 0, c = 0, m = Math.min(a.t,this.t);
  700. while(i < m) {
  701. c += this[i]+a[i];
  702. r[i++] = c&this.DM;
  703. c >>= this.DB;
  704. }
  705. if(a.t < this.t) {
  706. c += a.s;
  707. while(i < this.t) {
  708. c += this[i];
  709. r[i++] = c&this.DM;
  710. c >>= this.DB;
  711. }
  712. c += this.s;
  713. }
  714. else {
  715. c += this.s;
  716. while(i < a.t) {
  717. c += a[i];
  718. r[i++] = c&this.DM;
  719. c >>= this.DB;
  720. }
  721. c += a.s;
  722. }
  723. r.s = (c<0)?-1:0;
  724. if(c > 0) r[i++] = c;
  725. else if(c < -1) r[i++] = this.DV+c;
  726. r.t = i;
  727. r.clamp();
  728. }
  729. // (public) this + a
  730. function bnAdd(a) { var r = nbi(); this.addTo(a,r); return r; }
  731. // (public) this - a
  732. function bnSubtract(a) { var r = nbi(); this.subTo(a,r); return r; }
  733. // (public) this * a
  734. function bnMultiply(a) { var r = nbi(); this.multiplyTo(a,r); return r; }
  735. // (public) this^2
  736. function bnSquare() { var r = nbi(); this.squareTo(r); return r; }
  737. // (public) this / a
  738. function bnDivide(a) { var r = nbi(); this.divRemTo(a,r,null); return r; }
  739. // (public) this % a
  740. function bnRemainder(a) { var r = nbi(); this.divRemTo(a,null,r); return r; }
  741. // (public) [this/a,this%a]
  742. function bnDivideAndRemainder(a) {
  743. var q = nbi(), r = nbi();
  744. this.divRemTo(a,q,r);
  745. return new Array(q,r);
  746. }
  747. // (protected) this *= n, this >= 0, 1 < n < DV
  748. function bnpDMultiply(n) {
  749. this[this.t] = this.am(0,n-1,this,0,0,this.t);
  750. ++this.t;
  751. this.clamp();
  752. }
  753. // (protected) this += n << w words, this >= 0
  754. function bnpDAddOffset(n,w) {
  755. if(n == 0) return;
  756. while(this.t <= w) this[this.t++] = 0;
  757. this[w] += n;
  758. while(this[w] >= this.DV) {
  759. this[w] -= this.DV;
  760. if(++w >= this.t) this[this.t++] = 0;
  761. ++this[w];
  762. }
  763. }
  764. // A "null" reducer
  765. function NullExp() {}
  766. function nNop(x) { return x; }
  767. function nMulTo(x,y,r) { x.multiplyTo(y,r); }
  768. function nSqrTo(x,r) { x.squareTo(r); }
  769. NullExp.prototype.convert = nNop;
  770. NullExp.prototype.revert = nNop;
  771. NullExp.prototype.mulTo = nMulTo;
  772. NullExp.prototype.sqrTo = nSqrTo;
  773. // (public) this^e
  774. function bnPow(e) { return this.exp(e,new NullExp()); }
  775. // (protected) r = lower n words of "this * a", a.t <= n
  776. // "this" should be the larger one if appropriate.
  777. function bnpMultiplyLowerTo(a,n,r) {
  778. var i = Math.min(this.t+a.t,n);
  779. r.s = 0; // assumes a,this >= 0
  780. r.t = i;
  781. while(i > 0) r[--i] = 0;
  782. var j;
  783. for(j = r.t-this.t; i < j; ++i) r[i+this.t] = this.am(0,a[i],r,i,0,this.t);
  784. for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a[i],r,i,0,n-i);
  785. r.clamp();
  786. }
  787. // (protected) r = "this * a" without lower n words, n > 0
  788. // "this" should be the larger one if appropriate.
  789. function bnpMultiplyUpperTo(a,n,r) {
  790. --n;
  791. var i = r.t = this.t+a.t-n;
  792. r.s = 0; // assumes a,this >= 0
  793. while(--i >= 0) r[i] = 0;
  794. for(i = Math.max(n-this.t,0); i < a.t; ++i)
  795. r[this.t+i-n] = this.am(n-i,a[i],r,0,0,this.t+i-n);
  796. r.clamp();
  797. r.drShiftTo(1,r);
  798. }
  799. // Barrett modular reduction
  800. function Barrett(m) {
  801. // setup Barrett
  802. this.r2 = nbi();
  803. this.q3 = nbi();
  804. BigInteger.ONE.dlShiftTo(2*m.t,this.r2);
  805. this.mu = this.r2.divide(m);
  806. this.m = m;
  807. }
  808. function barrettConvert(x) {
  809. if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m);
  810. else if(x.compareTo(this.m) < 0) return x;
  811. else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; }
  812. }
  813. function barrettRevert(x) { return x; }
  814. // x = x mod m (HAC 14.42)
  815. function barrettReduce(x) {
  816. x.drShiftTo(this.m.t-1,this.r2);
  817. if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); }
  818. this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);
  819. this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);
  820. while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1);
  821. x.subTo(this.r2,x);
  822. while(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
  823. }
  824. // r = x^2 mod m; x != r
  825. function barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
  826. // r = x*y mod m; x,y != r
  827. function barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
  828. Barrett.prototype.convert = barrettConvert;
  829. Barrett.prototype.revert = barrettRevert;
  830. Barrett.prototype.reduce = barrettReduce;
  831. Barrett.prototype.mulTo = barrettMulTo;
  832. Barrett.prototype.sqrTo = barrettSqrTo;
  833. // (public) this^e % m (HAC 14.85)
  834. function bnModPow(e,m) {
  835. var i = e.bitLength(), k, r = nbv(1), z;
  836. if(i <= 0) return r;
  837. else if(i < 18) k = 1;
  838. else if(i < 48) k = 3;
  839. else if(i < 144) k = 4;
  840. else if(i < 768) k = 5;
  841. else k = 6;
  842. if(i < 8)
  843. z = new Classic(m);
  844. else if(m.isEven())
  845. z = new Barrett(m);
  846. else
  847. z = new Montgomery(m);
  848. // precomputation
  849. var g = new Array(), n = 3, k1 = k-1, km = (1<<k)-1;
  850. g[1] = z.convert(this);
  851. if(k > 1) {
  852. var g2 = nbi();
  853. z.sqrTo(g[1],g2);
  854. while(n <= km) {
  855. g[n] = nbi();
  856. z.mulTo(g2,g[n-2],g[n]);
  857. n += 2;
  858. }
  859. }
  860. var j = e.t-1, w, is1 = true, r2 = nbi(), t;
  861. i = nbits(e[j])-1;
  862. while(j >= 0) {
  863. if(i >= k1) w = (e[j]>>(i-k1))&km;
  864. else {
  865. w = (e[j]&((1<<(i+1))-1))<<(k1-i);
  866. if(j > 0) w |= e[j-1]>>(this.DB+i-k1);
  867. }
  868. n = k;
  869. while((w&1) == 0) { w >>= 1; --n; }
  870. if((i -= n) < 0) { i += this.DB; --j; }
  871. if(is1) { // ret == 1, don't bother squaring or multiplying it
  872. g[w].copyTo(r);
  873. is1 = false;
  874. }
  875. else {
  876. while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; }
  877. if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; }
  878. z.mulTo(r2,g[w],r);
  879. }
  880. while(j >= 0 && (e[j]&(1<<i)) == 0) {
  881. z.sqrTo(r,r2); t = r; r = r2; r2 = t;
  882. if(--i < 0) { i = this.DB-1; --j; }
  883. }
  884. }
  885. return z.revert(r);
  886. }
  887. // (public) gcd(this,a) (HAC 14.54)
  888. function bnGCD(a) {
  889. var x = (this.s<0)?this.negate():this.clone();
  890. var y = (a.s<0)?a.negate():a.clone();
  891. if(x.compareTo(y) < 0) { var t = x; x = y; y = t; }
  892. var i = x.getLowestSetBit(), g = y.getLowestSetBit();
  893. if(g < 0) return x;
  894. if(i < g) g = i;
  895. if(g > 0) {
  896. x.rShiftTo(g,x);
  897. y.rShiftTo(g,y);
  898. }
  899. while(x.signum() > 0) {
  900. if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x);
  901. if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y);
  902. if(x.compareTo(y) >= 0) {
  903. x.subTo(y,x);
  904. x.rShiftTo(1,x);
  905. }
  906. else {
  907. y.subTo(x,y);
  908. y.rShiftTo(1,y);
  909. }
  910. }
  911. if(g > 0) y.lShiftTo(g,y);
  912. return y;
  913. }
  914. // (protected) this % n, n < 2^26
  915. function bnpModInt(n) {
  916. if(n <= 0) return 0;
  917. var d = this.DV%n, r = (this.s<0)?n-1:0;
  918. if(this.t > 0)
  919. if(d == 0) r = this[0]%n;
  920. else for(var i = this.t-1; i >= 0; --i) r = (d*r+this[i])%n;
  921. return r;
  922. }
  923. // (public) 1/this % m (HAC 14.61)
  924. function bnModInverse(m) {
  925. var ac = m.isEven();
  926. if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO;
  927. var u = m.clone(), v = this.clone();
  928. var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1);
  929. while(u.signum() != 0) {
  930. while(u.isEven()) {
  931. u.rShiftTo(1,u);
  932. if(ac) {
  933. if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); }
  934. a.rShiftTo(1,a);
  935. }
  936. else if(!b.isEven()) b.subTo(m,b);
  937. b.rShiftTo(1,b);
  938. }
  939. while(v.isEven()) {
  940. v.rShiftTo(1,v);
  941. if(ac) {
  942. if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); }
  943. c.rShiftTo(1,c);
  944. }
  945. else if(!d.isEven()) d.subTo(m,d);
  946. d.rShiftTo(1,d);
  947. }
  948. if(u.compareTo(v) >= 0) {
  949. u.subTo(v,u);
  950. if(ac) a.subTo(c,a);
  951. b.subTo(d,b);
  952. }
  953. else {
  954. v.subTo(u,v);
  955. if(ac) c.subTo(a,c);
  956. d.subTo(b,d);
  957. }
  958. }
  959. if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO;
  960. if(d.compareTo(m) >= 0) return d.subtract(m);
  961. if(d.signum() < 0) d.addTo(m,d); else return d;
  962. if(d.signum() < 0) return d.add(m); else return d;
  963. }
  964. 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];
  965. var lplim = (1<<26)/lowprimes[lowprimes.length-1];
  966. // (public) test primality with certainty >= 1-.5^t
  967. function bnIsProbablePrime(t) {
  968. var i, x = this.abs();
  969. if(x.t == 1 && x[0] <= lowprimes[lowprimes.length-1]) {
  970. for(i = 0; i < lowprimes.length; ++i)
  971. if(x[0] == lowprimes[i]) return true;
  972. return false;
  973. }
  974. if(x.isEven()) return false;
  975. i = 1;
  976. while(i < lowprimes.length) {
  977. var m = lowprimes[i], j = i+1;
  978. while(j < lowprimes.length && m < lplim) m *= lowprimes[j++];
  979. m = x.modInt(m);
  980. while(i < j) if(m%lowprimes[i++] == 0) return false;
  981. }
  982. return x.millerRabin(t);
  983. }
  984. // (protected) true if probably prime (HAC 4.24, Miller-Rabin)
  985. function bnpMillerRabin(t) {
  986. var n1 = this.subtract(BigInteger.ONE);
  987. var k = n1.getLowestSetBit();
  988. if(k <= 0) return false;
  989. var r = n1.shiftRight(k);
  990. t = (t+1)>>1;
  991. if(t > lowprimes.length) t = lowprimes.length;
  992. var a = nbi();
  993. for(var i = 0; i < t; ++i) {
  994. //Pick bases at random, instead of starting at 2
  995. a.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);
  996. var y = a.modPow(r,this);
  997. if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
  998. var j = 1;
  999. while(j++ < k && y.compareTo(n1) != 0) {
  1000. y = y.modPowInt(2,this);
  1001. if(y.compareTo(BigInteger.ONE) == 0) return false;
  1002. }
  1003. if(y.compareTo(n1) != 0) return false;
  1004. }
  1005. }
  1006. return true;
  1007. }
  1008. // protected
  1009. BigInteger.prototype.chunkSize = bnpChunkSize;
  1010. BigInteger.prototype.toRadix = bnpToRadix;
  1011. BigInteger.prototype.fromRadix = bnpFromRadix;
  1012. BigInteger.prototype.fromNumber = bnpFromNumber;
  1013. BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
  1014. BigInteger.prototype.changeBit = bnpChangeBit;
  1015. BigInteger.prototype.addTo = bnpAddTo;
  1016. BigInteger.prototype.dMultiply = bnpDMultiply;
  1017. BigInteger.prototype.dAddOffset = bnpDAddOffset;
  1018. BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
  1019. BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
  1020. BigInteger.prototype.modInt = bnpModInt;
  1021. BigInteger.prototype.millerRabin = bnpMillerRabin;
  1022. // public
  1023. BigInteger.prototype.clone = bnClone;
  1024. BigInteger.prototype.intValue = bnIntValue;
  1025. BigInteger.prototype.byteValue = bnByteValue;
  1026. BigInteger.prototype.shortValue = bnShortValue;
  1027. BigInteger.prototype.signum = bnSigNum;
  1028. BigInteger.prototype.toByteArray = bnToByteArray;
  1029. BigInteger.prototype.equals = bnEquals;
  1030. BigInteger.prototype.min = bnMin;
  1031. BigInteger.prototype.max = bnMax;
  1032. BigInteger.prototype.and = bnAnd;
  1033. BigInteger.prototype.or = bnOr;
  1034. BigInteger.prototype.xor = bnXor;
  1035. BigInteger.prototype.andNot = bnAndNot;
  1036. BigInteger.prototype.not = bnNot;
  1037. BigInteger.prototype.shiftLeft = bnShiftLeft;
  1038. BigInteger.prototype.shiftRight = bnShiftRight;
  1039. BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
  1040. BigInteger.prototype.bitCount = bnBitCount;
  1041. BigInteger.prototype.testBit = bnTestBit;
  1042. BigInteger.prototype.setBit = bnSetBit;
  1043. BigInteger.prototype.clearBit = bnClearBit;
  1044. BigInteger.prototype.flipBit = bnFlipBit;
  1045. BigInteger.prototype.add = bnAdd;
  1046. BigInteger.prototype.subtract = bnSubtract;
  1047. BigInteger.prototype.multiply = bnMultiply;
  1048. BigInteger.prototype.divide = bnDivide;
  1049. BigInteger.prototype.remainder = bnRemainder;
  1050. BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
  1051. BigInteger.prototype.modPow = bnModPow;
  1052. BigInteger.prototype.modInverse = bnModInverse;
  1053. BigInteger.prototype.pow = bnPow;
  1054. BigInteger.prototype.gcd = bnGCD;
  1055. BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
  1056. // JSBN-specific extension
  1057. BigInteger.prototype.square = bnSquare;
  1058. // Expose the Barrett function
  1059. BigInteger.prototype.Barrett = Barrett
  1060. // BigInteger interfaces not implemented in jsbn:
  1061. // BigInteger(int signum, byte[] magnitude)
  1062. // double doubleValue()
  1063. // float floatValue()
  1064. // int hashCode()
  1065. // long longValue()
  1066. // static BigInteger valueOf(long val)
  1067. module.exports = BigInteger;