// Copyright (c) 2005  Tom Wu
// All Rights Reserved.
// See "LICENSE" for details.

// Basic JavaScript BN library - subset useful for RSA encryption.

var jsbn_dbits;var jsbn_canary=244837814094590;var jsbn_j_lm=((jsbn_canary&16777215)==15715070);function jsbn_BigInteger(e,d,f){if(e!=null){if("number"==typeof e){this.fromNumber(e,d,f)}else{if(d==null&&"string"!=typeof e){this.fromString(e,256)}else{this.fromString(e,d)}}}}function jsbn_nbi(){return new jsbn_BigInteger(null)}function jsbn_am1(f,a,b,e,h,g){while(--g>=0){var d=a*this[f++]+b[e]+h;h=Math.floor(d/67108864);b[e++]=d&67108863}return h}function jsbn_am2(f,q,r,e,o,a){var k=q&32767,p=q>>15;while(--a>=0){var d=this[f]&32767;var g=this[f++]>>15;var b=p*d+g*k;d=k*d+((b&32767)<<15)+r[e]+(o&1073741823);o=(d>>>30)+(b>>>15)+p*g+(o>>>30);r[e++]=d&1073741823}return o}function jsbn_am3(f,q,r,e,o,a){var k=q&16383,p=q>>14;while(--a>=0){var d=this[f]&16383;var g=this[f++]>>14;var b=p*d+g*k;d=k*d+((b&16383)<<14)+r[e]+o;o=(d>>28)+(b>>14)+p*g;r[e++]=d&268435455}return o}if(jsbn_j_lm&&(navigator.appName=="Microsoft Internet Explorer")){jsbn_BigInteger.prototype.am=jsbn_am2;jsbn_dbits=30}else{if(jsbn_j_lm&&(navigator.appName!="Netscape")){jsbn_BigInteger.prototype.am=jsbn_am1;jsbn_dbits=26}else{jsbn_BigInteger.prototype.am=jsbn_am3;jsbn_dbits=28}}jsbn_BigInteger.prototype.DB=jsbn_dbits;jsbn_BigInteger.prototype.DM=((1<<jsbn_dbits)-1);jsbn_BigInteger.prototype.DV=(1<<jsbn_dbits);var jsbn_BI_FP=52;jsbn_BigInteger.prototype.FV=Math.pow(2,jsbn_BI_FP);jsbn_BigInteger.prototype.F1=jsbn_BI_FP-jsbn_dbits;jsbn_BigInteger.prototype.F2=2*jsbn_dbits-jsbn_BI_FP;var jsbn_BI_RM="0123456789abcdefghijklmnopqrstuvwxyz";var jsbn_BI_RC=new Array();var jsbn_rr,jsbn_vv;jsbn_rr="0".charCodeAt(0);for(jsbn_vv=0;jsbn_vv<=9;++jsbn_vv){jsbn_BI_RC[jsbn_rr++]=jsbn_vv}jsbn_rr="a".charCodeAt(0);for(jsbn_vv=10;jsbn_vv<36;++jsbn_vv){jsbn_BI_RC[jsbn_rr++]=jsbn_vv}jsbn_rr="A".charCodeAt(0);for(jsbn_vv=10;jsbn_vv<36;++jsbn_vv){jsbn_BI_RC[jsbn_rr++]=jsbn_vv}function jsbn_int2char(a){return jsbn_BI_RM.charAt(a)}function jsbn_intAt(b,a){var d=jsbn_BI_RC[b.charCodeAt(a)];return(d==null)?-1:d}function jsbn_bnpCopyTo(b){for(var a=this.t-1;a>=0;--a){b[a]=this[a]}b.t=this.t;b.s=this.s}function jsbn_bnpFromInt(a){this.t=1;this.s=(a<0)?-1:0;if(a>0){this[0]=a}else{if(a<-1){this[0]=a+DV}else{this.t=0}}}function jsbn_nbv(a){var b=jsbn_nbi();b.fromInt(a);return b}function jsbn_bnpFromString(h,c){var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==256){e=8}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{this.fromRadix(h,c);return}}}}}}this.t=0;this.s=0;var g=h.length,d=false,f=0;while(--g>=0){var a=(e==8)?h[g]&255:jsbn_intAt(h,g);if(a<0){if(h.charAt(g)=="-"){d=true}continue}d=false;if(f==0){this[this.t++]=a}else{if(f+e>this.DB){this[this.t-1]|=(a&((1<<(this.DB-f))-1))<<f;this[this.t++]=(a>>(this.DB-f))}else{this[this.t-1]|=a<<f}}f+=e;if(f>=this.DB){f-=this.DB}}if(e==8&&(h[0]&128)!=0){this.s=-1;if(f>0){this[this.t-1]|=((1<<(this.DB-f))-1)<<f}}this.clamp();if(d){jsbn_BigInteger.ZERO.subTo(this,this)}}function jsbn_bnpClamp(){var a=this.s&this.DM;while(this.t>0&&this[this.t-1]==a){--this.t}}function jsbn_bnToString(c){if(this.s<0){return"-"+this.negate().toString(c)}var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{return this.toRadix(c)}}}}}var g=(1<<e)-1,l,a=false,h="",f=this.t;var j=this.DB-(f*this.DB)%e;if(f-->0){if(j<this.DB&&(l=this[f]>>j)>0){a=true;h=jsbn_int2char(l)}while(f>=0){if(j<e){l=(this[f]&((1<<j)-1))<<(e-j);l|=this[--f]>>(j+=this.DB-e)}else{l=(this[f]>>(j-=e))&g;if(j<=0){j+=this.DB;--f}}if(l>0){a=true}if(a){h+=jsbn_int2char(l)}}}return a?h:"0"}function jsbn_bnNegate(){var a=jsbn_nbi();jsbn_BigInteger.ZERO.subTo(this,a);return a}function jsbn_bnAbs(){return(this.s<0)?this.negate():this}function jsbn_bnCompareTo(b){var d=this.s-b.s;if(d!=0){return d}var c=this.t;d=c-b.t;if(d!=0){return d}while(--c>=0){if((d=this[c]-b[c])!=0){return d}}return 0}function jsbn_nbits(a){var c=1,b;if((b=a>>>16)!=0){a=b;c+=16}if((b=a>>8)!=0){a=b;c+=8}if((b=a>>4)!=0){a=b;c+=4}if((b=a>>2)!=0){a=b;c+=2}if((b=a>>1)!=0){a=b;c+=1}return c}function jsbn_bnBitLength(){if(this.t<=0){return 0}return this.DB*(this.t-1)+jsbn_nbits(this[this.t-1]^(this.s&this.DM))}function jsbn_bnpDLShiftTo(c,b){var a;for(a=this.t-1;a>=0;--a){b[a+c]=this[a]}for(a=c-1;a>=0;--a){b[a]=0}b.t=this.t+c;b.s=this.s}function jsbn_bnpDRShiftTo(c,b){for(var a=c;a<this.t;++a){b[a-c]=this[a]}b.t=Math.max(this.t-c,0);b.s=this.s}function jsbn_bnpLShiftTo(j,e){var b=j%this.DB;var a=this.DB-b;var g=(1<<a)-1;var f=Math.floor(j/this.DB),h=(this.s<<b)&this.DM,d;for(d=this.t-1;d>=0;--d){e[d+f+1]=(this[d]>>a)|h;h=(this[d]&g)<<b}for(d=f-1;d>=0;--d){e[d]=0}e[f]=h;e.t=this.t+f+1;e.s=this.s;e.clamp()}function jsbn_bnpRShiftTo(g,d){d.s=this.s;var e=Math.floor(g/this.DB);if(e>=this.t){d.t=0;return}var b=g%this.DB;var a=this.DB-b;var f=(1<<b)-1;d[0]=this[e]>>b;for(var c=e+1;c<this.t;++c){d[c-e-1]|=(this[c]&f)<<a;d[c-e]=this[c]>>b}if(b>0){d[this.t-e-1]|=(this.s&f)<<a}d.t=this.t-e;d.clamp()}function jsbn_bnpSubTo(d,f){var e=0,g=0,b=Math.min(d.t,this.t);while(e<b){g+=this[e]-d[e];f[e++]=g&this.DM;g>>=this.DB}if(d.t<this.t){g-=d.s;while(e<this.t){g+=this[e];f[e++]=g&this.DM;g>>=this.DB}g+=this.s}else{g+=this.s;while(e<d.t){g-=d[e];f[e++]=g&this.DM;g>>=this.DB}g-=d.s}f.s=(g<0)?-1:0;if(g<-1){f[e++]=this.DV+g}else{if(g>0){f[e++]=g}}f.t=e;f.clamp()}function jsbn_bnpMultiplyTo(c,e){var b=this.abs(),f=c.abs();var d=b.t;e.t=d+f.t;while(--d>=0){e[d]=0}for(d=0;d<f.t;++d){e[d+b.t]=b.am(0,f[d],e,d,0,b.t)}e.s=0;e.clamp();if(this.s!=c.s){jsbn_BigInteger.ZERO.subTo(e,e)}}function jsbn_bnpSquareTo(d){var a=this.abs();var b=d.t=2*a.t;while(--b>=0){d[b]=0}for(b=0;b<a.t-1;++b){var e=a.am(b,a[b],d,2*b,0,1);if((d[b+a.t]+=a.am(b+1,2*a[b],d,2*b+1,e,a.t-b-1))>=a.DV){d[b+a.t]-=a.DV;d[b+a.t+1]=1}}if(d.t>0){d[d.t-1]+=a.am(b,a[b],d,2*b,0,1)}d.s=0;d.clamp()}function jsbn_bnpDivRemTo(n,h,g){var w=n.abs();if(w.t<=0){return}var k=this.abs();if(k.t<w.t){if(h!=null){h.fromInt(0)}if(g!=null){this.copyTo(g)}return}if(g==null){g=jsbn_nbi()}var d=jsbn_nbi(),a=this.s,l=n.s;var v=this.DB-jsbn_nbits(w[w.t-1]);if(v>0){w.lShiftTo(v,d);k.lShiftTo(v,g)}else{w.copyTo(d);k.copyTo(g)}var p=d.t;var b=d[p-1];if(b==0){return}var o=b*(1<<this.F1)+((p>1)?d[p-2]>>this.F2:0);var A=this.FV/o,z=(1<<this.F1)/o,x=1<<this.F2;var u=g.t,s=u-p,f=(h==null)?jsbn_nbi():h;d.dlShiftTo(s,f);if(g.compareTo(f)>=0){g[g.t++]=1;g.subTo(f,g)}jsbn_BigInteger.ONE.dlShiftTo(p,f);f.subTo(d,d);while(d.t<p){d[d.t++]=0}while(--s>=0){var c=(g[--u]==b)?this.DM:Math.floor(g[u]*A+(g[u-1]+x)*z);if((g[u]+=d.am(0,c,g,s,0,p))<c){d.dlShiftTo(s,f);g.subTo(f,g);while(g[u]<--c){g.subTo(f,g)}}}if(h!=null){g.drShiftTo(p,h);if(a!=l){jsbn_BigInteger.ZERO.subTo(h,h)}}g.t=p;g.clamp();if(v>0){g.rShiftTo(v,g)}if(a<0){jsbn_BigInteger.ZERO.subTo(g,g)}}function jsbn_bnMod(b){var c=jsbn_nbi();this.abs().divRemTo(b,null,c);if(this.s<0&&c.compareTo(jsbn_BigInteger.ZERO)>0){b.subTo(c,c)}return c}function jsbn_Classic(a){this.m=a}function jsbn_cConvert(a){if(a.s<0||a.compareTo(this.m)>=0){return a.mod(this.m)}else{return a}}function jsbn_cRevert(a){return a}function jsbn_cReduce(a){a.divRemTo(this.m,null,a)}function jsbn_cMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}function jsbn_cSqrTo(a,b){a.squareTo(b);this.reduce(b)}jsbn_Classic.prototype.convert=jsbn_cConvert;jsbn_Classic.prototype.revert=jsbn_cRevert;jsbn_Classic.prototype.reduce=jsbn_cReduce;jsbn_Classic.prototype.mulTo=jsbn_cMulTo;jsbn_Classic.prototype.sqrTo=jsbn_cSqrTo;function jsbn_bnpInvDigit(){if(this.t<1){return 0}var a=this[0];if((a&1)==0){return 0}var b=a&3;b=(b*(2-(a&15)*b))&15;b=(b*(2-(a&255)*b))&255;b=(b*(2-(((a&65535)*b)&65535)))&65535;b=(b*(2-a*b%this.DV))%this.DV;return(b>0)?this.DV-b:-b}function jsbn_Montgomery(a){this.m=a;this.mp=a.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<(a.DB-15))-1;this.mt2=2*a.t}function jsbn_montConvert(a){var b=jsbn_nbi();a.abs().dlShiftTo(this.m.t,b);b.divRemTo(this.m,null,b);if(a.s<0&&b.compareTo(jsbn_BigInteger.ZERO)>0){this.m.subTo(b,b)}return b}function jsbn_montRevert(a){var b=jsbn_nbi();a.copyTo(b);this.reduce(b);return b}function jsbn_montReduce(a){while(a.t<=this.mt2){a[a.t++]=0}for(var c=0;c<this.m.t;++c){var b=a[c]&32767;var d=(b*this.mpl+(((b*this.mph+(a[c]>>15)*this.mpl)&this.um)<<15))&a.DM;b=c+this.m.t;a[b]+=this.m.am(0,d,a,c,0,this.m.t);while(a[b]>=a.DV){a[b]-=a.DV;a[++b]++}}a.clamp();a.drShiftTo(this.m.t,a);if(a.compareTo(this.m)>=0){a.subTo(this.m,a)}}function jsbn_montSqrTo(a,b){a.squareTo(b);this.reduce(b)}function jsbn_montMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}jsbn_Montgomery.prototype.convert=jsbn_montConvert;jsbn_Montgomery.prototype.revert=jsbn_montRevert;jsbn_Montgomery.prototype.reduce=jsbn_montReduce;jsbn_Montgomery.prototype.mulTo=jsbn_montMulTo;jsbn_Montgomery.prototype.sqrTo=jsbn_montSqrTo;function jsbn_bnpIsEven(){return((this.t>0)?(this[0]&1):this.s)==0}function jsbn_bnpExp(h,j){if(h>4294967295||h<1){return jsbn_BigInteger.ONE}var f=jsbn_nbi(),a=jsbn_nbi(),d=j.convert(this),c=jsbn_nbits(h)-1;d.copyTo(f);while(--c>=0){j.sqrTo(f,a);if((h&(1<<c))>0){j.mulTo(a,d,f)}else{var b=f;f=a;a=b}}return j.revert(f)}function jsbn_bnModPowInt(b,a){var c;if(b<256||a.isEven()){c=new jsbn_Classic(a)}else{c=new jsbn_Montgomery(a)}return this.exp(b,c)}jsbn_BigInteger.prototype.copyTo=jsbn_bnpCopyTo;jsbn_BigInteger.prototype.fromInt=jsbn_bnpFromInt;jsbn_BigInteger.prototype.fromString=jsbn_bnpFromString;jsbn_BigInteger.prototype.clamp=jsbn_bnpClamp;jsbn_BigInteger.prototype.dlShiftTo=jsbn_bnpDLShiftTo;jsbn_BigInteger.prototype.drShiftTo=jsbn_bnpDRShiftTo;jsbn_BigInteger.prototype.lShiftTo=jsbn_bnpLShiftTo;jsbn_BigInteger.prototype.rShiftTo=jsbn_bnpRShiftTo;jsbn_BigInteger.prototype.subTo=jsbn_bnpSubTo;jsbn_BigInteger.prototype.multiplyTo=jsbn_bnpMultiplyTo;jsbn_BigInteger.prototype.squareTo=jsbn_bnpSquareTo;jsbn_BigInteger.prototype.divRemTo=jsbn_bnpDivRemTo;jsbn_BigInteger.prototype.invDigit=jsbn_bnpInvDigit;jsbn_BigInteger.prototype.isEven=jsbn_bnpIsEven;jsbn_BigInteger.prototype.exp=jsbn_bnpExp;jsbn_BigInteger.prototype.toString=jsbn_bnToString;jsbn_BigInteger.prototype.negate=jsbn_bnNegate;jsbn_BigInteger.prototype.abs=jsbn_bnAbs;jsbn_BigInteger.prototype.compareTo=jsbn_bnCompareTo;jsbn_BigInteger.prototype.bitLength=jsbn_bnBitLength;jsbn_BigInteger.prototype.mod=jsbn_bnMod;jsbn_BigInteger.prototype.modPowInt=jsbn_bnModPowInt;jsbn_BigInteger.ZERO=jsbn_nbv(0);jsbn_BigInteger.ONE=jsbn_nbv(1);