PS3_Toolset/files/biginteger.pmin.js

1 line
50 KiB
JavaScript

function assignToObject(t,e){return"function"!=typeof Object.assign&&Object.defineProperties(Object,{assign:{value:function(t){"use strict";if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),r=1;r<arguments.length;r++){var n=arguments[r];if(null!=n)for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},writable:!0,configurable:!0}}),Object.assign(t,e)}function cloneObject(t){var e={};for(var r in t)null!=t[r]&&"object"==typeof t[r]?e[r]=cloneObject(t[r]):e[r]=t[r];return e}"function"!=typeof Object.create&&(Object.create=function(t,e){function r(t){t&&Object.defineProperties(this,t)}return r.prototype=t,new r(e)}),Object.keys||(Object.keys=function(t){if(t!==Object(t))throw new TypeError("Object.keys called on a non-object");var e,r=[];for(e in t)Object.prototype.hasOwnProperty.call(t,e)&&r.push(e);return r}),String.prototype.startsWith||(String.prototype.startsWith=function(t,e){return e=!e||e<0?0:+e,this.substring(e,e+t.length)===t}),String.prototype.endsWith||(String.prototype.endsWith=function(t,e){return(void 0===e||e>this.length)&&(e=this.length),this.substring(e-t.length,e)===t}),Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),Array.prototype.forEach||(Array.prototype.forEach=function(t,e){e=e||window;for(var r=0;r<this.length;r++)t.call(e,this[r],r,this)}),window.NodeList&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=function(t,e){e=e||window;for(var r=0;r<this.length;r++)t.call(e,this[r],r,this)}),Number.prototype.toString64=function(){return("0000000000000000"+this.toString(16)).substr(-16)},Number.prototype.toString32=function(){return("00000000"+this.toString(16)).substr(-8)},Number.prototype.toString16=function(){return("0000"+this.toString(16)).substr(-4)},Number.prototype.toString8=function(){return("00"+this.toString(16)).substr(-2)},Number.prototype.noExponents=function(){var t=String(this).split(/[eE]/);if(1===t.length)return t[0];var e="",r=this<0?"-":"",n=t[0].replace(".",""),i=Number(t[1])+1;if(i<0){for(e=r+"0.";i++;)e+="0";return e+n.replace(/^\-/,"")}for(i-=n.length;i--;)e+="0";return n+e},String.prototype.repeat=function(t){return new Array(t+1).join(this)},String.prototype.fromAscii=function(){for(var t="",e=0;e<this.length/2;)t+=String.fromCharCode(parseInt(this.substr(2*e,2),16)),e++;return t},String.prototype.toAscii=function(){for(var t="",e=0;e<this.length;e++)t+=this.charCodeAt(e).toString16();return t},String.prototype.toAscii8=function(){for(var t="",e=0;e<this.length;e++)t+=this.charCodeAt(e).toString8();for(var r=0;r<t.length%8;r++)t+="00";return t+"00000000"};var bigInt=function(s){var y=1e7,h=7,e=9007199254740992,r=m(e),f=Math.log(e);function p(t,e){return void 0===t?p[0]:void 0===e||10==+e?W(t):G(t,e)}function g(t,e){this.value=t,this.sign=e,this.isSmall=!1}function d(t){this.value=t,this.sign=t<0,this.isSmall=!0}function v(t){return-e<t&&t<e}function m(t){return t<1e7?[t]:t<1e14?[t%1e7,Math.floor(t/1e7)]:[t%1e7,Math.floor(t/1e7)%1e7,Math.floor(t/1e14)]}function b(t){w(t);var e=t.length;if(e<4&&M(t,r)<0)switch(e){case 0:return 0;case 1:return t[0];case 2:return t[0]+t[1]*y;default:return t[0]+(t[1]+t[2]*y)*y}return t}function w(t){for(var e=t.length;0===t[--e];);t.length=e+1}function j(t){for(var e=new Array(t),r=-1;++r<t;)e[r]=0;return e}function S(t){return 0<t?Math.floor(t):Math.ceil(t)}function n(t,e){for(var r,n=t.length,i=e.length,o=new Array(n),s=0,a=y,c=0;c<i;c++)s=a<=(r=t[c]+e[c]+s)?1:0,o[c]=r-s*a;for(;c<n;)s=(r=t[c]+s)===a?1:0,o[c++]=r-s*a;return 0<s&&o.push(s),o}function A(t,e){return t.length>=e.length?n(t,e):n(e,t)}function i(t,e){for(var r,n=t.length,i=new Array(n),o=y,s=0;s<n;s++)r=t[s]-o+e,e=Math.floor(r/o),i[s]=r-e*o,e+=1;for(;0<e;)i[s++]=e%o,e=Math.floor(e/o);return i}function x(t,e){for(var r,n=t.length,i=e.length,o=new Array(n),s=0,a=y,c=0;c<i;c++)s=(r=t[c]-s-e[c])<0?(r+=a,1):0,o[c]=r;for(c=i;c<n;c++){if(!((r=t[c]-s)<0)){o[c++]=r;break}r+=a,o[c]=r}for(;c<n;c++)o[c]=t[c];return w(o),o}function c(t,e,r){for(var n,i=t.length,o=new Array(i),s=-e,a=y,c=0;c<i;c++)n=t[c]+s,s=Math.floor(n/a),n%=a,o[c]=n<0?n+a:n;return"number"==typeof(o=b(o))?(r&&(o=-o),new d(o)):new g(o,r)}function _(t,e){for(var r,n,i,o=t.length,s=e.length,a=j(o+s),c=y,l=0;l<o;++l){i=t[l];for(var u=0;u<s;++u)r=i*e[u]+a[l+u],n=Math.floor(r/c),a[l+u]=r-n*c,a[l+u+1]+=n}return w(a),a}function E(t,e){for(var r,n=t.length,i=new Array(n),o=y,s=0,a=0;a<n;a++)r=t[a]*e+s,s=Math.floor(r/o),i[a]=r-s*o;for(;0<s;)i[a++]=s%o,s=Math.floor(s/o);return i}function L(t,e){for(var r=[];0<e--;)r.push(0);return r.concat(t)}function o(t,e,r){return new g(t<y?E(e,t):_(e,m(t)),r)}function a(t){for(var e,r,n,i=t.length,o=j(i+i),s=y,a=0;a<i;a++){r=0-(n=t[a])*n;for(var c=a;c<i;c++)e=n*t[c]*2+o[a+c]+r,r=Math.floor(e/s),o[a+c]=e-r*s;o[a+i]=r}return w(o),o}function I(t,e){for(var r,n,i=t.length,o=j(i),s=y,a=0,c=i-1;0<=c;--c)a=(n=a*s+t[c])-(r=S(n/e))*e,o[c]=0|r;return[o,0|a]}function B(t,e){var r,n=W(e),i=t.value,o=n.value;if(0===o)throw new Error("Cannot divide by zero");if(t.isSmall)return n.isSmall?[new d(S(i/o)),new d(i%o)]:[p[0],t];if(n.isSmall){if(1===o)return[t,p[0]];if(-1==o)return[t.negate(),p[0]];var s=Math.abs(o);if(s<y){l=b((r=I(i,s))[0]);var a=r[1];return t.sign&&(a=-a),"number"==typeof l?(t.sign!==n.sign&&(l=-l),[new d(l),new d(a)]):[new g(l,t.sign!==n.sign),new d(a)]}o=m(s)}var c=M(i,o);if(-1===c)return[p[0],t];if(0===c)return[p[t.sign===n.sign?1:-1],p[0]];l=(r=(i.length+o.length<=200?function(t,e){var r,n,i,o,s,a,c,l=t.length,u=e.length,h=y,f=j(e.length),p=e[u-1],g=Math.ceil(h/(2*p)),d=E(t,g),v=E(e,g);for(d.length<=l&&d.push(0),v.push(0),p=v[u-1],n=l-u;0<=n;n--){for(r=h-1,d[n+u]!==p&&(r=Math.floor((d[n+u]*h+d[n+u-1])/p)),o=i=0,a=v.length,s=0;s<a;s++)i+=r*v[s],c=Math.floor(i/h),o+=d[n+s]-(i-c*h),i=c,o=o<0?(d[n+s]=o+h,-1):(d[n+s]=o,0);for(;0!==o;){for(--r,s=i=0;s<a;s++)i=(i+=d[n+s]-h+v[s])<0?(d[n+s]=i+h,0):(d[n+s]=i,1);o+=i}f[n]=r}return d=I(d,g)[0],[b(f),b(d)]}:function(t,e){for(var r,n,i,o,s,a=t.length,c=e.length,l=[],u=[],h=y;a;)if(u.unshift(t[--a]),w(u),M(u,e)<0)l.push(0);else{i=u[(n=u.length)-1]*h+u[n-2],o=e[c-1]*h+e[c-2],c<n&&(i=(i+1)*h),r=Math.ceil(i/o);do{if(M(s=E(e,r),u)<=0)break;r--}while(r);l.push(r),u=x(u,s)}return l.reverse(),[b(l),b(u)]})(i,o))[0];var l,u=t.sign!==n.sign,h=r[1],f=t.sign;return[l="number"==typeof l?(u&&(l=-l),new d(l)):new g(l,u),h="number"==typeof h?(f&&(h=-h),new d(h)):new g(h,f)]}function M(t,e){if(t.length!==e.length)return t.length>e.length?1:-1;for(var r=t.length-1;0<=r;r--)if(t[r]!==e[r])return t[r]>e[r]?1:-1;return 0}function l(t){var e=t.abs();return!e.isUnit()&&(!!(e.equals(2)||e.equals(3)||e.equals(5))||!(e.isEven()||e.isDivisibleBy(3)||e.isDivisibleBy(5))&&(!!e.lesser(49)||void 0))}function u(t,e){for(var r,n,i,o,s=t.prev(),a=s;a.isEven();)a=a.divide(2);for(i=0;i<e.length;i++)if(!t.lesser(e[i])&&!(o=bigInt(e[i]).modPow(a,t)).equals(p[1])&&!o.equals(s)){for(n=!0,r=a;n&&r.lesser(s);r=r.multiply(2))(o=o.square().mod(t)).equals(s)&&(n=!1);if(n)return!1}return!0}g.prototype=Object.create(p.prototype),d.prototype=Object.create(p.prototype),g.prototype.plus=g.prototype.add=function(t){var e=W(t);if(this.sign!==e.sign)return this.subtract(e.negate());var r=this.value,n=e.value;return e.isSmall?new g(i(r,Math.abs(n)),this.sign):new g(A(r,n),this.sign)},d.prototype.plus=d.prototype.add=function(t){var e=W(t),r=this.value;if(r<0!==e.sign)return this.subtract(e.negate());var n=e.value;if(e.isSmall){if(v(r+n))return new d(r+n);n=m(Math.abs(n))}return new g(i(n,Math.abs(r)),r<0)},g.prototype.minus=g.prototype.subtract=function(t){var e=W(t);if(this.sign!==e.sign)return this.add(e.negate());var r,n,i,o,s=this.value,a=e.value;return e.isSmall?c(s,Math.abs(a),this.sign):(r=s,n=a,i=this.sign,0<=M(r,n)?o=x(r,n):(o=x(n,r),i=!i),"number"==typeof(o=b(o))?(i&&(o=-o),new d(o)):new g(o,i))},d.prototype.minus=d.prototype.subtract=function(t){var e=W(t),r=this.value;if(r<0!==e.sign)return this.add(e.negate());var n=e.value;return e.isSmall?new d(r-n):c(n,Math.abs(r),0<=r)},g.prototype.negate=function(){return new g(this.value,!this.sign)},d.prototype.negate=function(){var t=this.sign,e=new d(-this.value);return e.sign=!t,e},g.prototype.abs=function(){return new g(this.value,!1)},d.prototype.abs=function(){return new d(Math.abs(this.value))},g.prototype.times=g.prototype.multiply=function(t){var e,r,n,i=W(t),o=this.value,s=i.value,a=this.sign!==i.sign;if(i.isSmall){if(0===s)return p[0];if(1===s)return this;if(-1===s)return this.negate();if((e=Math.abs(s))<y)return new g(E(o,e),a);s=m(e)}return r=o.length,n=s.length,new g((0<-.012*r-.012*n+15e-6*r*n?function t(e,r){var n=Math.max(e.length,r.length);if(n<=30)return _(e,r);n=Math.ceil(n/2);var i=e.slice(n),o=e.slice(0,n),s=r.slice(n),a=r.slice(0,n),c=t(o,a),l=t(i,s),u=t(A(o,i),A(a,s)),h=A(A(c,L(x(x(u,c),l),n)),L(l,2*n));return w(h),h}:_)(o,s),a)},d.prototype._multiplyBySmall=function(t){return v(t.value*this.value)?new d(t.value*this.value):o(Math.abs(t.value),m(Math.abs(this.value)),this.sign!==t.sign)},g.prototype._multiplyBySmall=function(t){return 0===t.value?p[0]:1===t.value?this:-1===t.value?this.negate():o(Math.abs(t.value),this.value,this.sign!==t.sign)},d.prototype.times=d.prototype.multiply=function(t){return W(t)._multiplyBySmall(this)},g.prototype.square=function(){return new g(a(this.value),!1)},d.prototype.square=function(){var t=this.value*this.value;return v(t)?new d(t):new g(a(m(Math.abs(this.value))),!1)},d.prototype.divmod=g.prototype.divmod=function(t){var e=B(this,t);return{quotient:e[0],remainder:e[1]}},d.prototype.over=d.prototype.divide=g.prototype.over=g.prototype.divide=function(t){return B(this,t)[0]},d.prototype.remainder=d.prototype.mod=g.prototype.remainder=g.prototype.mod=function(t){return B(this,t)[1]},g.prototype.pow=function(t){var e,r,n,i=W(t),o=this.value,s=i.value;if(0===s)return p[1];if(0===o)return p[0];if(1===o)return p[1];if(-1===o)return i.isEven()?p[1]:p[-1];if(i.sign)return p[0];if(!i.isSmall)throw new Error("The exponent "+i.toString()+" is too large.");if(this.isSmall&&v(e=Math.pow(o,s)))return new d(S(e));for(r=this,n=p[1];!0&s&&(n=n.times(r),--s),0!==s;)s/=2,r=r.square();return n},d.prototype.pow=g.prototype.pow,d.prototype.modPow=g.prototype.modPow=function(t,e){if(t=W(t),(e=W(e)).isZero())throw new Error("Cannot take modPow with modulus 0");for(var r=p[1],n=this.mod(e);t.isPositive();){if(n.isZero())return p[0];t.isOdd()&&(r=r.multiply(n).mod(e)),t=t.divide(2),n=n.square().mod(e)}return r},g.prototype.compareAbs=function(t){var e=W(t),r=this.value,n=e.value;return e.isSmall?1:M(r,n)},d.prototype.compareAbs=function(t){var e=W(t),r=Math.abs(this.value),n=e.value;return e.isSmall?r===(n=Math.abs(n))?0:n<r?1:-1:-1},g.prototype.compareTo=g.prototype.compare=function(t){if(t===1/0)return-1;if(t===-1/0)return 1;var e=W(t),r=this.value,n=e.value;return this.sign!==e.sign?e.sign?1:-1:e.isSmall?this.sign?-1:1:M(r,n)*(this.sign?-1:1)},d.prototype.compareTo=d.prototype.compare=function(t){if(t===1/0)return-1;if(t===-1/0)return 1;var e=W(t),r=this.value,n=e.value;return e.isSmall?r==n?0:n<r?1:-1:r<0!==e.sign?r<0?-1:1:r<0?1:-1},d.prototype.eq=d.prototype.equals=g.prototype.eq=g.prototype.equals=function(t){return 0===this.compare(t)},d.prototype.neq=d.prototype.notEquals=g.prototype.neq=g.prototype.notEquals=function(t){return 0!==this.compare(t)},d.prototype.gt=d.prototype.greater=g.prototype.gt=g.prototype.greater=function(t){return 0<this.compare(t)},d.prototype.lt=d.prototype.lesser=g.prototype.lt=g.prototype.lesser=function(t){return this.compare(t)<0},d.prototype.geq=d.prototype.greaterOrEquals=g.prototype.geq=g.prototype.greaterOrEquals=function(t){return 0<=this.compare(t)},d.prototype.leq=d.prototype.lesserOrEquals=g.prototype.leq=g.prototype.lesserOrEquals=function(t){return this.compare(t)<=0},g.prototype.isEven=function(){return 0==(1&this.value[0])},d.prototype.isEven=function(){return 0==(1&this.value)},g.prototype.isOdd=function(){return 1==(1&this.value[0])},d.prototype.isOdd=function(){return 1==(1&this.value)},g.prototype.isPositive=function(){return!this.sign},d.prototype.isPositive=function(){return 0<this.value},g.prototype.isNegative=function(){return this.sign},d.prototype.isNegative=function(){return this.value<0},g.prototype.isUnit=function(){return!1},d.prototype.isUnit=function(){return 1===Math.abs(this.value)},g.prototype.isZero=function(){return!1},d.prototype.isZero=function(){return 0===this.value},d.prototype.isDivisibleBy=g.prototype.isDivisibleBy=function(t){var e=W(t),r=e.value;return 0!==r&&(1===r||(2===r?this.isEven():this.mod(e).equals(p[0])))},d.prototype.isPrime=g.prototype.isPrime=function(){var t=l(this);return t!==s?t:u(this.abs(),[2,325,9375,28178,450775,9780504,1795265022])},d.prototype.isProbablePrime=g.prototype.isProbablePrime=function(t){var e=l(this);if(e!==s)return e;for(var r=this.abs(),n=t===s?5:t,i=[],o=0;o<n;o++)i.push(bigInt.randBetween(2,r.minus(2)));return u(r,i)},d.prototype.modInv=g.prototype.modInv=function(t){for(var e,r,n,i=bigInt.zero,o=bigInt.one,s=W(t),a=this.abs();!a.equals(bigInt.zero);)e=s.divide(a),r=i,n=s,i=o,s=a,o=r.subtract(e.multiply(o)),a=n.subtract(e.multiply(a));if(!s.equals(1))throw new Error(this.toString()+" and "+t.toString()+" are not co-prime");return-1===i.compare(0)&&(i=i.add(t)),this.isNegative()?i.negate():i},g.prototype.next=function(){var t=this.value;return this.sign?c(t,1,this.sign):new g(i(t,1),this.sign)},d.prototype.next=function(){var t=this.value;return t+1<e?new d(t+1):new g(r,!1)},g.prototype.prev=function(){var t=this.value;return this.sign?new g(i(t,1),!0):c(t,1,this.sign)},d.prototype.prev=function(){var t=this.value;return-e<t-1?new d(t-1):new g(r,!0)};for(var C=[1];2*C[C.length-1]<=y;)C.push(2*C[C.length-1]);var k=C.length,O=C[k-1];function N(t){return("number"==typeof t||"string"==typeof t)&&+Math.abs(t)<=y||t instanceof g&&t.value.length<=1}function q(t,e,r){e=W(e);for(var n=t.isNegative(),i=e.isNegative(),o=n?t.not():t,s=i?e.not():e,a=0,c=0,l=null,u=null,h=[];!o.isZero()||!s.isZero();)a=(l=B(o,O))[1].toJSNumber(),n&&(a=O-1-a),c=(u=B(s,O))[1].toJSNumber(),i&&(c=O-1-c),o=l[0],s=u[0],h.push(r(a,c));for(var f=0!==r(n?1:0,i?1:0)?bigInt(-1):bigInt(0),p=h.length-1;0<=p;--p)f=f.multiply(O).add(bigInt(h[p]));return f}d.prototype.shiftLeft=g.prototype.shiftLeft=function(t){if(!N(t))throw new Error(String(t)+" is too large for shifting.");if((t=+t)<0)return this.shiftRight(-t);var e=this;if(e.isZero())return e;for(;k<=t;)e=e.multiply(O),t-=k-1;return e.multiply(C[t])},d.prototype.shiftRight=g.prototype.shiftRight=function(t){var e;if(!N(t))throw new Error(String(t)+" is too large for shifting.");if((t=+t)<0)return this.shiftLeft(-t);for(var r=this;k<=t;){if(r.isZero()||r.isNegative()&&r.isUnit())return r;r=(e=B(r,O))[1].isNegative()?e[0].prev():e[0],t-=k-1}return(e=B(r,C[t]))[1].isNegative()?e[0].prev():e[0]},d.prototype.not=g.prototype.not=function(){return this.negate().prev()},d.prototype.and=g.prototype.and=function(t){return q(this,t,function(t,e){return t&e})},d.prototype.or=g.prototype.or=function(t){return q(this,t,function(t,e){return t|e})},d.prototype.xor=g.prototype.xor=function(t){return q(this,t,function(t,e){return t^e})};var P=1<<30,U=(y&-y)*(y&-y)|P;function R(t){var e=t.value,r="number"==typeof e?e|P:e[0]+e[1]*y|U;return r&-r}function T(t,e){return t=W(t),e=W(e),t.greater(e)?t:e}function z(t,e){return t=W(t),e=W(e),t.lesser(e)?t:e}function D(t,e){if(t=W(t).abs(),e=W(e).abs(),t.equals(e))return t;if(t.isZero())return e;if(e.isZero())return t;for(var r,n,i=p[1];t.isEven()&&e.isEven();)r=Math.min(R(t),R(e)),t=t.divide(r),e=e.divide(r),i=i.multiply(r);for(;t.isEven();)t=t.divide(R(t));do{for(;e.isEven();)e=e.divide(R(e));t.greater(e)&&(n=e,e=t,t=n),e=e.subtract(t)}while(!e.isZero());return i.isUnit()?t:t.multiply(i)}d.prototype.bitLength=g.prototype.bitLength=function(){var t=this;return t.compareTo(bigInt(0))<0&&(t=t.negate().subtract(bigInt(1))),0===t.compareTo(bigInt(0))?bigInt(0):bigInt(function t(e,r){if(r.compareTo(e)<=0){var n=t(e,r.square(r)),i=n.p,o=n.e,s=i.multiply(r);return s.compareTo(e)<=0?{p:s,e:2*o+1}:{p:i,e:2*o}}return{p:bigInt(1),e:0}}(t,bigInt(2)).e).add(bigInt(1))};var G=function(t,e){for(var r=t.length,n=Math.abs(e),i=0;i<r;i++){if("-"!==(c=t[i].toLowerCase())&&/[a-z0-9]/.test(c)){if(/[0-9]/.test(c)&&n<=+c){if("1"===c&&1===n)continue;throw new Error(c+" is not a valid digit in base "+e+".")}if(c.charCodeAt(0)-87>=n)throw new Error(c+" is not a valid digit in base "+e+".")}}if(2<=e&&e<=36&&r<=f/Math.log(e)){var o=parseInt(t,e);if(isNaN(o))throw new Error(c+" is not a valid digit in base "+e+".");return new d(parseInt(t,e))}e=W(e);var s=[],a="-"===t[0];for(i=a?1:0;i<t.length;i++){var c,l=(c=t[i].toLowerCase()).charCodeAt(0);if(48<=l&&l<=57)s.push(W(c));else if(97<=l&&l<=122)s.push(W(c.charCodeAt(0)-87));else{if("<"!==c)throw new Error(c+" is not a valid character");for(var u=i;">"!==t[++i];);s.push(W(t.slice(u+1,i)))}}return Z(s,e,a)};function Z(t,e,r){for(var n=p[0],i=p[1],o=t.length-1;0<=o;o--)n=n.add(t[o].times(i)),i=i.times(e);return r?n.negate():n}function J(t){return t<=35?"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t):"<"+t+">"}function F(t,e){if((e=bigInt(e)).isZero()){if(t.isZero())return{value:[0],isNegative:!1};throw new Error("Cannot convert nonzero numbers to base 0.")}if(e.equals(-1)){if(t.isZero())return{value:[0],isNegative:!1};if(t.isNegative())return{value:[].concat.apply([],Array.apply(null,Array(-t)).map(Array.prototype.valueOf,[1,0])),isNegative:!1};var r=Array.apply(null,Array(t-1)).map(Array.prototype.valueOf,[0,1]);return r.unshift([1]),{value:[].concat.apply([],r),isNegative:!1}}var n=!1;if(t.isNegative()&&e.isPositive()&&(n=!0,t=t.abs()),e.equals(1))return t.isZero()?{value:[0],isNegative:!1}:{value:Array.apply(null,Array(+t)).map(Number.prototype.valueOf,1),isNegative:n};for(var i,o=[],s=t;s.isNegative()||0<=s.compareAbs(e);){s=(i=s.divmod(e)).quotient;var a=i.remainder;a.isNegative()&&(a=e.minus(a).abs(),s=s.next()),o.push(a.toJSNumber())}return o.push(s.toJSNumber()),{value:o.reverse(),isNegative:n}}function H(t,e){var r=F(t,e);return(r.isNegative?"-":"")+r.value.map(J).join("")}function V(t){if(v(+t)){var e=+t;if(e===S(e))return new d(e);throw new Error("Invalid integer: "+t)}var r="-"===t[0];r&&(t=t.slice(1));var n=t.split(/e/i);if(2<n.length)throw new Error("Invalid integer: "+n.join("e"));if(2===n.length){var i=n[1];if("+"===i[0]&&(i=i.slice(1)),(i=+i)!==S(i)||!v(i))throw new Error("Invalid integer: "+i+" is not a valid exponent.");var o=n[0],s=o.indexOf(".");if(0<=s&&(i-=o.length-s-1,o=o.slice(0,s)+o.slice(s+1)),i<0)throw new Error("Cannot include negative exponent part for integers");t=o+=new Array(i+1).join("0")}if(!/^([0-9][0-9]*)$/.test(t))throw new Error("Invalid integer: "+t);for(var a=[],c=t.length,l=h,u=c-l;0<c;)a.push(+t.slice(u,c)),(u-=l)<0&&(u=0),c-=l;return w(a),new g(a,r)}function W(t){return"number"==typeof t?function(t){if(v(t)){if(t!==S(t))throw new Error(t+" is not an integer.");return new d(t)}return V(t.toString())}(t):"string"==typeof t?V(t):t}g.prototype.toArray=function(t){return F(this,t)},d.prototype.toArray=function(t){return F(this,t)},g.prototype.toString=function(t){if(t===s&&(t=10),10!==t)return H(this,t);for(var e,r=this.value,n=r.length,i=String(r[--n]);0<=--n;)e=String(r[n]),i+="0000000".slice(e.length)+e;return(this.sign?"-":"")+i},d.prototype.toString=function(t){return t===s&&(t=10),10!=t?H(this,t):String(this.value)},g.prototype.toJSON=d.prototype.toJSON=function(){return this.toString()},g.prototype.toJSNumber=g.prototype.valueOf=function(){return parseInt(this.toString(),10)},d.prototype.toJSNumber=d.prototype.valueOf=function(){return this.value};for(var t=0;t<1e3;t++)p[t]=new d(t),0<t&&(p[-t]=new d(-t));return p.one=p[1],p.zero=p[0],p.minusOne=p[-1],p.max=T,p.min=z,p.gcd=D,p.lcm=function(t,e){return t=W(t).abs(),e=W(e).abs(),t.divide(D(t,e)).multiply(e)},p.isInstance=function(t){return t instanceof g||t instanceof d},p.randBetween=function(t,e){var r=z(t=W(t),e=W(e)),n=T(t,e).subtract(r).add(1);if(n.isSmall)return r.add(Math.floor(Math.random()*n));for(var i=[],o=!0,s=n.value.length-1;0<=s;s--){var a=o?n.value[s]:y,c=S(Math.random()*a);i.unshift(c),c<a&&(o=!1)}return i=b(i),r.add("number"==typeof i?new d(i):new g(i,!1))},p.isUInt64=function(t){return!(64<t.bitLength())},p.fromArray=function(t,e,r){return Z(t.map(W),W(e||10),r)},p}();function UInt64(t,e){function r(){}r.prototype=UInt64Prototype;var n=new r;return e=e||16,n.init(t,e),n.x64}var D,E,F,G,H,UInt64Prototype={init:function(t,e){var r=t;function n(t,e){if(64<t)throw new Error(e+"(): Number is not a 64bit integer")}function i(t){var e="0000000000000000"+t.toString(16);return e.substr(e.length-16,16)}this.x64=bigInt(t,e),n(this.x64.bitLength(),"init"),this.x64.toString64=function(){return("0000000000000000"+r).substr(-16)},this.x64.toString32=function(){return("00000000"+r).substr(-8)},this.x64.toString16=function(){return("0000"+r).substr(-4)},this.x64.toString8=function(){return("00"+r).substr(-2)},this.x64.add=function(t){var e=this.__proto__.add.call(this,t);return n(e.bitLength(),"add"),new UInt64(e.toString(16))},this.x64.plus=function(t){return this.add.call(this,t)},this.x64.subtract=function(t){var e=this.__proto__.subtract.call(this,t);return n(e.bitLength(),"subtract"),new UInt64(e.toString(16))},this.x64.minus=function(t){return this.subtract.call(this,t)},this.x64.negate=function(){var t=this.__proto__.negate.call(this);return n(t.bitLength(),"negate"),new UInt64(t.toString(16))},this.x64.abs=function(){var t=this.__proto__.abs.call(this);return n(t.bitLength(),"abs"),new UInt64(t.toString(16))},this.x64.multiply=function(t){var e=this.__proto__.multiply.call(this,t);return n(e.bitLength(),"multiply"),new UInt64(e.toString(16))},this.x64.times=function(t){return this.multiply.call(this,t)},this.x64._multiplyBySmall=function(t){var e=this.__proto__._multiplyBySmall.call(this,t);return n(e.bitLength(),"_multiplyBySmall"),new UInt64(e.toString(16))},this.x64.square=function(){var t=this.__proto__.square.call(this);return n(t.bitLength(),"square"),new UInt64(t.toString(16))},this.x64.divide=function(t){var e=this.__proto__.divide.call(this,t);return n(e.bitLength(),"divide"),new UInt64(e.toString(16))},this.x64.mod=function(t){var e=this.__proto__.mod.call(this,t);return n(e.bitLength(),"mod"),new UInt64(e.toString(16))},this.x64.pow=function(t){var e=this.__proto__.pow.call(this,t);return n(e.bitLength(),"pow"),new UInt64(e.toString(16))},this.x64.modInv=function(t){var e=this.__proto__.modInv.call(this,t);return n(e.bitLength(),"modInv"),new UInt64(e.toString(16))},this.x64.next=function(){var t=this.__proto__.next.call(this);return n(t.bitLength(),"next"),new UInt64(t.toString(16))},this.x64.prev=function(){var t=this.__proto__.prev.call(this);return n(t.bitLength(),"prev"),new UInt64(t.toString(16))},this.x64.shiftLeft=function(t){var e=this.__proto__.shiftLeft.call(this,t);return n(e.bitLength(),"shiftLeft"),new UInt64(e.toString(16))},this.x64.shiftRight=function(t){var e=this.__proto__.shiftRight.call(this,t);return n(e.bitLength(),"shiftRight"),new UInt64(e.toString(16))},this.x64.and=function(t){var e=this.__proto__.and.call(this,t);return n(e.bitLength(),"and"),new UInt64(e.toString(16))},this.x64.or=function(t){var e=this.__proto__.or.call(this,t);return n(e.bitLength(),"or"),new UInt64(e.toString(16))},this.x64.not=function(){var t=this.__proto__.not.call(this);return n(t.bitLength(),"not"),new UInt64(t.toString(16))},this.x64.xor=function(t){var e=this.__proto__.xor.call(this,t);return n(e.bitLength(),"xor"),new UInt64(e.toString(16))},this.x64.hi32=function(){return n(this.bitLength(),"hi32"),parseInt(i(this).substr(0,8),16)},this.x64.lo32=function(){return n(this.bitLength(),"lo32"),parseInt(i(this).substr(8,8),16)}}},sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};function t(t,e,r){if(4!==e.length)throw new sjcl.exception.invalid("invalid aes block size");var n=t.b[r],i=e[0]^n[0],o=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var a,c,l=n.length/4-2,u=4,h=[0,0,0,0],f=t.s[r];t=f[0];for(var p=f[1],g=f[2],d=f[3],v=f[4],y=0;y<l;y++)f=t[i>>>24]^p[o>>16&255]^g[s>>8&255]^d[255&e]^n[u],a=t[o>>>24]^p[s>>16&255]^g[e>>8&255]^d[255&i]^n[u+1],c=t[s>>>24]^p[e>>16&255]^g[i>>8&255]^d[255&o]^n[u+2],e=t[e>>>24]^p[i>>16&255]^g[o>>8&255]^d[255&s]^n[u+3],u+=4,i=f,o=a,s=c;for(y=0;y<4;y++)h[r?3&-y:y]=v[i>>>24]<<24^v[o>>16&255]<<16^v[s>>8&255]<<8^v[255&e]^n[u++],f=i,i=o,o=s,s=e,e=f;return h}function u(t,e){for(var r,n,i=t.F,o=t.b,s=i[0],a=i[1],c=i[2],l=i[3],u=i[4],h=i[5],f=i[6],p=i[7],g=0;g<64;g++)r=(r=g<16?e[g]:(r=e[g+1&15],n=e[g+14&15],e[15&g]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[15&g]+e[g+9&15]|0))+p+(u>>>6^u>>>11^u>>>25^u<<26^u<<21^u<<7)+(f^u&(h^f))+o[g],p=f,f=h,h=u,u=l+r|0,l=c,c=a,s=r+((a=s)&c^l&(a^c))+(a>>>2^a>>>13^a>>>22^a<<30^a<<19^a<<10)|0;i[0]=i[0]+s|0,i[1]=i[1]+a|0,i[2]=i[2]+c|0,i[3]=i[3]+l|0,i[4]=i[4]+u|0,i[5]=i[5]+h|0,i[6]=i[6]+f|0,i[7]=i[7]+p|0}function A(t,e){var r,n=sjcl.random.K[t],i=[];for(r in n)n.hasOwnProperty(r)&&i.push(n[r]);for(r=0;r<i.length;r++)i[r](e)}function C(t,e){"undefined"!=typeof window&&window.performance&&"function"==typeof window.performance.now?t.addEntropy(window.performance.now(),e,"loadtime"):t.addEntropy((new Date).valueOf(),e,"loadtime")}function y(t){t.b=z(t).concat(z(t)),t.L=new sjcl.cipher.aes(t.b)}function z(t){for(var e=0;e<4&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function B(t,e){return function(){e.apply(t,arguments)}}sjcl.cipher.aes=function(t){this.s[0][0][0]||this.O();var e,r,n,i=this.s[0][4],o=this.s[1],s=t.length,a=1;if(4!==s&&6!==s&&8!==s)throw new sjcl.exception.invalid("invalid aes key size");for(this.b=[r=t.slice(0),n=[]],t=s;t<4*s+28;t++)e=r[t-1],(0==t%s||8===s&&4==t%s)&&(e=i[e>>>24]<<24^i[e>>16&255]<<16^i[e>>8&255]<<8^i[255&e],0==t%s&&(e=e<<8^e>>>24^a<<24,a=a<<1^283*(a>>7))),r[t]=r[t-s]^e;for(s=0;t;s++,t--)e=r[3&s?t:t-4],n[s]=t<=4||s<4?e:o[0][i[e>>>24]]^o[1][i[e>>16&255]]^o[2][i[e>>8&255]]^o[3][i[255&e]]},sjcl.cipher.aes.prototype={encrypt:function(e){return t(this,e,0)},decrypt:function(e){return t(this,e,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){for(var t,e,r,n,i,o,s=this.s[0],a=this.s[1],c=s[4],l=a[4],u=[],h=[],f=0;f<256;f++)h[(u[f]=f<<1^283*(f>>7))^f]=f;for(t=e=0;!c[t];t^=r||1,e=h[e]||1)for(i=(i=e^e<<1^e<<2^e<<3^e<<4)>>8^255&i^99,o=16843009*(n=u[f=u[r=u[l[c[t]=i]=t]]])^65537*f^257*r^16843008*t,n=257*u[i]^16843008*i,f=0;f<4;f++)s[f][t]=n=n<<24^n>>>8,a[f][i]=o=o<<24^o>>>8;for(f=0;f<5;f++)s[f]=s[f].slice(0),a[f]=a[f].slice(0)}},sjcl.bitArray={bitSlice:function(t,e,r){return t=sjcl.bitArray.$(t.slice(e/32),32-(31&e)).slice(1),void 0===r?t:sjcl.bitArray.clamp(t,r-e)},extract:function(t,e,r){var n=Math.floor(-e-r&31);return(-32&(e+r-1^e)?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n)&(1<<r)-1},concat:function(t,e){if(0===t.length||0===e.length)return t.concat(e);var r=t[t.length-1],n=sjcl.bitArray.getPartial(r);return 32===n?t.concat(e):sjcl.bitArray.$(e,n,0|r,t.slice(0,t.length-1))},bitLength:function(t){var e=t.length;return 0===e?0:32*(e-1)+sjcl.bitArray.getPartial(t[e-1])},clamp:function(t,e){if(32*t.length<e)return t;var r=(t=t.slice(0,Math.ceil(e/32))).length;return e&=31,0<r&&e&&(t[r-1]=sjcl.bitArray.partial(e,t[r-1]&2147483648>>e-1,1)),t},partial:function(t,e,r){return 32===t?e:(r?0|e:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(sjcl.bitArray.bitLength(t)!==sjcl.bitArray.bitLength(e))return!1;for(var r=0,n=0;n<t.length;n++)r|=t[n]^e[n];return 0===r},$:function(t,e,r,n){var i=0;for(void 0===n&&(n=[]);32<=e;e-=32)n.push(r),r=0;if(0===e)return n.concat(t);for(i=0;i<t.length;i++)n.push(r|t[i]>>>e),r=t[i]<<32-e;return i=t.length?t[t.length-1]:0,t=sjcl.bitArray.getPartial(i),n.push(sjcl.bitArray.partial(e+t&31,32<e+t?r:n.pop(),1)),n},i:function(t,e){return[t[0]^e[0],t[1]^e[1],t[2]^e[2],t[3]^e[3]]},byteswapM:function(t){for(var e,r=0;r<t.length;++r)e=t[r],t[r]=e>>>24|e>>>8&65280|(65280&e)<<8|e<<24;return t}},sjcl.codec.utf8String={fromBits:function(t){for(var e,r="",n=sjcl.bitArray.bitLength(t),i=0;i<n/8;i++)0==(3&i)&&(e=t[i/4]),r+=String.fromCharCode(e>>>8>>>8>>>8),e<<=8;return decodeURIComponent(escape(r))},toBits:function(t){t=unescape(encodeURIComponent(t));for(var e=[],r=0,n=0;n<t.length;n++)r=r<<8|t.charCodeAt(n),3==(3&n)&&(e.push(r),r=0);return 3&n&&e.push(sjcl.bitArray.partial(8*(3&n),r)),e}},sjcl.codec.hex={fromBits:function(t){for(var e="",r=0;r<t.length;r++)e+=(0xf00000000000+(0|t[r])).toString(16).substr(4);return e.substr(0,sjcl.bitArray.bitLength(t)/4)},toBits:function(t){var e,r=[],n=(t=t.replace(/\s|0x/g,"")).length;for(t+="00000000",e=0;e<t.length;e+=8)r.push(0^parseInt(t.substr(e,8),16));return sjcl.bitArray.clamp(r,4*n)}},sjcl.codec.base32={B:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",X:"0123456789ABCDEFGHIJKLMNOPQRSTUV",BITS:32,BASE:5,REMAINING:27,fromBits:function(t,e,r){var n=sjcl.codec.base32.BASE,i=sjcl.codec.base32.REMAINING,o="",s=0,a=sjcl.codec.base32.B,c=0,l=sjcl.bitArray.bitLength(t);for(r&&(a=sjcl.codec.base32.X),r=0;o.length*n<l;)o+=a.charAt((c^t[r]>>>s)>>>i),s<n?(c=t[r]<<n-s,s+=i,r++):(c<<=n,s-=n);for(;7&o.length&&!e;)o+="=";return o},toBits:function(t,e){t=t.replace(/\s|=/g,"").toUpperCase();var r,n,i=sjcl.codec.base32.BITS,o=sjcl.codec.base32.BASE,s=sjcl.codec.base32.REMAINING,a=[],c=0,l=sjcl.codec.base32.B,u=0,h="base32";for(e&&(l=sjcl.codec.base32.X,h="base32hex"),r=0;r<t.length;r++){if((n=l.indexOf(t.charAt(r)))<0){if(!e)try{return sjcl.codec.base32hex.toBits(t)}catch(t){}throw new sjcl.exception.invalid("this isn't "+h+"!")}s<c?(c-=s,a.push(u^n>>>c),u=n<<i-c):u^=n<<i-(c+=o)}return 56&c&&a.push(sjcl.bitArray.partial(56&c,u,1)),a}},sjcl.codec.base32hex={fromBits:function(t,e){return sjcl.codec.base32.fromBits(t,e,1)},toBits:function(t){return sjcl.codec.base32.toBits(t,1)}},sjcl.codec.base64={B:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(t,e,r){var n="",i=0,o=sjcl.codec.base64.B,s=0,a=sjcl.bitArray.bitLength(t);for(r&&(o=o.substr(0,62)+"-_"),r=0;6*n.length<a;)n+=o.charAt((s^t[r]>>>i)>>>26),i<6?(s=t[r]<<6-i,i+=26,r++):(s<<=6,i-=6);for(;3&n.length&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r,n,i=[],o=0,s=sjcl.codec.base64.B,a=0;for(e&&(s=s.substr(0,62)+"-_"),r=0;r<t.length;r++){if((n=s.indexOf(t.charAt(r)))<0)throw new sjcl.exception.invalid("this isn't base64!");26<o?(o-=26,i.push(a^n>>>o),a=n<<32-o):a^=n<<32-(o+=6)}return 56&o&&i.push(sjcl.bitArray.partial(56&o,a,1)),i}},sjcl.codec.base64url={fromBits:function(t){return sjcl.codec.base64.fromBits(t,1,1)},toBits:function(t){return sjcl.codec.base64.toBits(t,1)}},sjcl.hash.sha256=function(t){this.b[0]||this.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):this.reset()},sjcl.hash.sha256.hash=function(t){return(new sjcl.hash.sha256).update(t).finalize()},sjcl.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){"string"==typeof t&&(t=sjcl.codec.utf8String.toBits(t));var e=this.A=sjcl.bitArray.concat(this.A,t);if(i=this.l,9007199254740991<(t=this.l=i+sjcl.bitArray.bitLength(t)))throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");if("undefined"!=typeof Uint32Array){for(var r=new Uint32Array(e),n=0,i=512+i-(512+i&511);i<=t;i+=512)u(this,r.subarray(16*n,16*(n+1))),n+=1;e.splice(0,16*n)}else for(i=512+i-(512+i&511);i<=t;i+=512)u(this,e.splice(0,16));return this},finalize:function(){for(var t=this.A,e=this.F,r=(t=sjcl.bitArray.concat(t,[sjcl.bitArray.partial(1,1)])).length+2;15&r;r++)t.push(0);for(t.push(Math.floor(this.l/4294967296)),t.push(0|this.l);t.length;)u(this,t.splice(0,16));return this.reset(),e},Y:[],b:[],O:function(){function t(t){return 4294967296*(t-Math.floor(t))|0}for(var e,r,n=0,i=2;n<64;i++){for(r=!0,e=2;e*e<=i;e++)if(0==i%e){r=!1;break}r&&(n<8&&(this.Y[n]=t(Math.pow(i,.5))),this.b[n]=t(Math.pow(i,1/3)),n++)}}},sjcl.mode.ccm={name:"ccm",G:[],listenProgress:function(t){sjcl.mode.ccm.G.push(t)},unListenProgress:function(t){-1<(t=sjcl.mode.ccm.G.indexOf(t))&&sjcl.mode.ccm.G.splice(t,1)},fa:function(t){for(var e=sjcl.mode.ccm.G.slice(),r=0;r<e.length;r+=1)e[r](t)},encrypt:function(t,e,r,n,i){var o,s=e.slice(0),a=sjcl.bitArray,c=a.bitLength(r)/8,l=a.bitLength(s)/8;if(i=i||64,n=n||[],c<7)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(o=2;o<4&&l>>>8*o;o++);return o<15-c&&(o=15-c),r=a.clamp(r,8*(15-o)),e=sjcl.mode.ccm.V(t,e,r,n,i,o),s=sjcl.mode.ccm.C(t,s,r,e,i,o),a.concat(s.data,s.tag)},decrypt:function(t,e,r,n,i){i=i||64,n=n||[];var o=sjcl.bitArray,s=o.bitLength(r)/8,a=o.bitLength(e),c=o.clamp(e,a-i),l=o.bitSlice(e,a-i),a=(a-i)/8;if(s<7)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;e<4&&a>>>8*e;e++);if(e<15-s&&(e=15-s),r=o.clamp(r,8*(15-e)),c=sjcl.mode.ccm.C(t,c,r,l,i,e),t=sjcl.mode.ccm.V(t,c.data,r,n,i,e),!o.equal(c.tag,t))throw new sjcl.exception.corrupt("ccm: tag doesn't match");return c.data},na:function(t,e,r,n,i,o){var s=[],a=sjcl.bitArray,c=a.i;if(n=[a.partial(8,(e.length?64:0)|n-2<<2|o-1)],(n=a.concat(n,r))[3]|=i,n=t.encrypt(n),e.length)for((r=a.bitLength(e)/8)<=65279?s=[a.partial(16,r)]:r<=4294967295&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,e),e=0;e<s.length;e+=4)n=t.encrypt(c(n,s.slice(e,e+4).concat([0,0,0])));return n},V:function(t,e,r,n,i,o){var s=sjcl.bitArray,a=s.i;if((i/=8)%2||i<4||16<i)throw new sjcl.exception.invalid("ccm: invalid tag length");if(4294967295<n.length||4294967295<e.length)throw new sjcl.exception.bug("ccm: can't deal with 4GiB or more data");for(r=sjcl.mode.ccm.na(t,n,r,i,s.bitLength(e)/8,o),n=0;n<e.length;n+=4)r=t.encrypt(a(r,e.slice(n,n+4).concat([0,0,0])));return s.clamp(r,8*i)},C:function(t,e,r,n,i,o){var s=sjcl.bitArray,a=s.i,c=e.length,l=s.bitLength(e),u=c/50,h=u;if(r=s.concat([s.partial(8,o-1)],r).concat([0,0,0]).slice(0,4),n=s.bitSlice(a(n,t.encrypt(r)),0,i),!c)return{tag:n,data:[]};for(a=0;a<c;a+=4)u<a&&(sjcl.mode.ccm.fa(a/c),u+=h),r[3]++,i=t.encrypt(r),e[a]^=i[0],e[a+1]^=i[1],e[a+2]^=i[2],e[a+3]^=i[3];return{tag:n,data:s.clamp(e,l)}}},sjcl.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,i,o){if(128!==sjcl.bitArray.bitLength(r))throw new sjcl.exception.invalid("ocb iv must be 128 bits");var s,a=sjcl.mode.ocb2.S,c=sjcl.bitArray,l=c.i,u=[0,0,0,0];r=a(t.encrypt(r));var h,f=[];for(n=n||[],i=i||64,s=0;s+4<e.length;s+=4)u=l(u,h=e.slice(s,s+4)),f=f.concat(l(r,t.encrypt(l(r,h)))),r=a(r);return h=e.slice(s),e=c.bitLength(h),s=t.encrypt(l(r,[0,0,0,e])),h=c.clamp(l(h.concat([0,0,0]),s),e),u=l(u,l(h.concat([0,0,0]),s)),u=t.encrypt(l(u,l(r,a(r)))),n.length&&(u=l(u,o?n:sjcl.mode.ocb2.pmac(t,n))),f.concat(c.concat(h,c.clamp(u,i)))},decrypt:function(t,e,r,n,i,o){if(128!==sjcl.bitArray.bitLength(r))throw new sjcl.exception.invalid("ocb iv must be 128 bits");i=i||64;var s,a,c=sjcl.mode.ocb2.S,l=sjcl.bitArray,u=l.i,h=[0,0,0,0],f=c(t.encrypt(r)),p=sjcl.bitArray.bitLength(e)-i,g=[];for(n=n||[],r=0;r+4<p/32;r+=4)s=u(f,t.decrypt(u(f,e.slice(r,r+4)))),h=u(h,s),g=g.concat(s),f=c(f);if(a=p-32*r,s=t.encrypt(u(f,[0,0,0,a])),s=u(s,l.clamp(e.slice(r),a).concat([0,0,0])),h=u(h,s),h=t.encrypt(u(h,u(f,c(f)))),n.length&&(h=u(h,o?n:sjcl.mode.ocb2.pmac(t,n))),!l.equal(l.clamp(h,i),l.bitSlice(e,p)))throw new sjcl.exception.corrupt("ocb: tag doesn't match");return g.concat(l.clamp(s,a))},pmac:function(t,e){for(var r=sjcl.mode.ocb2.S,n=sjcl.bitArray,i=n.i,o=[0,0,0,0],s=i(s=t.encrypt([0,0,0,0]),r(r(s))),a=0;a+4<e.length;a+=4)s=r(s),o=i(o,t.encrypt(i(s,e.slice(a,a+4))));return a=e.slice(a),n.bitLength(a)<128&&(s=i(s,r(s)),a=n.concat(a,[-2147483648,0,0,0])),o=i(o,a),t.encrypt(i(r(i(s,r(s))),o))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}},sjcl.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,i){var o=e.slice(0);return e=sjcl.bitArray,n=n||[],t=sjcl.mode.gcm.C(!0,t,o,n,r,i||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,i){var o=e.slice(0),s=sjcl.bitArray,a=s.bitLength(o);if(n=n||[],o=(i=i||128)<=a?(e=s.bitSlice(o,a-i),s.bitSlice(o,0,a-i)):(e=o,[]),t=sjcl.mode.gcm.C(!1,t,o,n,r,i),!s.equal(t.tag,e))throw new sjcl.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){for(var r,n,i=sjcl.bitArray.i,o=[0,0,0,0],s=e.slice(0),a=0;a<128;a++){for((r=0!=(t[Math.floor(a/32)]&1<<31-a%32))&&(o=i(o,s)),n=0!=(1&s[3]),r=3;0<r;r--)s[r]=s[r]>>>1|(1&s[r-1])<<31;s[0]>>>=1,n&&(s[0]^=-520093696)}return o},j:function(t,e,r){var n,i=r.length;for(e=e.slice(0),n=0;n<i;n+=4)e[0]^=4294967295&r[n],e[1]^=4294967295&r[n+1],e[2]^=4294967295&r[n+2],e[3]^=4294967295&r[n+3],e=sjcl.mode.gcm.ka(e,t);return e},C:function(t,e,r,n,i,o){var s,a,c,l=sjcl.bitArray,u=r.length,h=l.bitLength(r),f=l.bitLength(n),p=l.bitLength(i),g=e.encrypt([0,0,0,0]);for(i=96===p?(i=i.slice(0),l.concat(i,[1])):(i=sjcl.mode.gcm.j(g,[0,0,0,0],i),sjcl.mode.gcm.j(g,i,[0,0,Math.floor(p/4294967296),4294967295&p])),p=sjcl.mode.gcm.j(g,[0,0,0,0],n),c=i.slice(0),n=p.slice(0),t||(n=sjcl.mode.gcm.j(g,p,r)),a=0;a<u;a+=4)c[3]++,s=e.encrypt(c),r[a]^=s[0],r[a+1]^=s[1],r[a+2]^=s[2],r[a+3]^=s[3];return r=l.clamp(r,h),t&&(n=sjcl.mode.gcm.j(g,p,r)),t=[Math.floor(f/4294967296),4294967295&f,Math.floor(h/4294967296),4294967295&h],n=sjcl.mode.gcm.j(g,n,t),s=e.encrypt(i),n[0]^=s[0],n[1]^=s[1],n[2]^=s[2],n[3]^=s[3],{tag:l.bitSlice(n,0,o),data:r}}},sjcl.misc.hmac=function(t,e){this.W=e=e||sjcl.hash.sha256;var r,n=[[],[]],i=e.prototype.blockSize/32;for(this.w=[new e,new e],t.length>i&&(t=e.hash(t)),r=0;r<i;r++)n[0][r]=909522486^t[r],n[1][r]=1549556828^t[r];this.w[0].update(n[0]),this.w[1].update(n[1]),this.R=new e(this.w[0])},sjcl.misc.hmac.prototype.encrypt=sjcl.misc.hmac.prototype.mac=function(t){if(this.aa)throw new sjcl.exception.invalid("encrypt on already updated hmac called!");return this.update(t),this.digest(t)},sjcl.misc.hmac.prototype.reset=function(){this.R=new this.W(this.w[0]),this.aa=!1},sjcl.misc.hmac.prototype.update=function(t){this.aa=!0,this.R.update(t)},sjcl.misc.hmac.prototype.digest=function(){var t=this.R.finalize(),t=new this.W(this.w[1]).update(t).finalize();return this.reset(),t},sjcl.misc.pbkdf2=function(t,e,r,n,i){if(r=r||1e4,n<0||r<0)throw new sjcl.exception.invalid("invalid params to pbkdf2");"string"==typeof t&&(t=sjcl.codec.utf8String.toBits(t)),"string"==typeof e&&(e=sjcl.codec.utf8String.toBits(e)),t=new(i=i||sjcl.misc.hmac)(t);for(var o,s,a,c=[],l=sjcl.bitArray,u=1;32*c.length<(n||1);u++){for(i=o=t.encrypt(l.concat(e,[u])),s=1;s<r;s++)for(o=t.encrypt(o),a=0;a<o.length;a++)i[a]^=o[a];c=c.concat(i)}return n&&(c=l.clamp(c,n)),c},sjcl.prng=function(t){this.c=[new sjcl.hash.sha256],this.m=[0],this.P=0,this.H={},this.N=0,this.U={},this.Z=this.f=this.o=this.ha=0,this.b=[0,0,0,0,0,0,0,0],this.h=[0,0,0,0],this.L=void 0,this.M=t,this.D=!1,this.K={progress:{},seeded:{}},this.u=this.ga=0,this.I=1,this.J=2,this.ca=65536,this.T=[0,48,64,96,128,192,256,384,512,768,1024],this.da=3e4,this.ba=80},sjcl.prng.prototype={randomWords:function(t,e){var r,n=[],i=this.isReady(e);if(i===this.u)throw new sjcl.exception.notReady("generator isn't seeded");if(i&this.J){i=!(i&this.I),r=[];var o,s=0;for(this.Z=r[0]=(new Date).valueOf()+this.da,o=0;o<16;o++)r.push(4294967296*Math.random()|0);for(o=0;o<this.c.length&&(r=r.concat(this.c[o].finalize()),s+=this.m[o],this.m[o]=0,i||!(this.P&1<<o));o++);for(this.P>=1<<this.c.length&&(this.c.push(new sjcl.hash.sha256),this.m.push(0)),this.f-=s,s>this.o&&(this.o=s),this.P++,this.b=sjcl.hash.sha256.hash(this.b.concat(r)),this.L=new sjcl.cipher.aes(this.b),i=0;i<4&&(this.h[i]=this.h[i]+1|0,!this.h[i]);i++);}for(i=0;i<t;i+=4)0==(i+1)%this.ca&&y(this),r=z(this),n.push(r[0],r[1],r[2],r[3]);return y(this),n.slice(0,t)},setDefaultParanoia:function(t,e){if(0===t&&"Setting paranoia=0 will ruin your security; use it only for testing"!==e)throw new sjcl.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing");this.M=t},addEntropy:function(t,e,r){r=r||"user";var n,i=(new Date).valueOf(),o=this.H[r],s=this.isReady(),a=0,c=this.U[r];switch(void 0===c&&(c=this.U[r]=this.ha++),void 0===o&&(o=this.H[r]=0),this.H[r]=(this.H[r]+1)%this.c.length,typeof t){case"number":void 0===e&&(e=1),this.c[o].update([c,this.N++,1,e,i,1,0|t]);break;case"object":if("[object Uint32Array]"===(r=Object.prototype.toString.call(t))){for(n=[],r=0;r<t.length;r++)n.push(t[r]);t=n}else for("[object Array]"!==r&&(a=1),r=0;r<t.length&&!a;r++)"number"!=typeof t[r]&&(a=1);if(!a){if(void 0===e)for(r=e=0;r<t.length;r++)for(n=t[r];0<n;)e++,n>>>=1;this.c[o].update([c,this.N++,2,e,i,t.length].concat(t))}break;case"string":void 0===e&&(e=t.length),this.c[o].update([c,this.N++,3,e,i,t.length]),this.c[o].update(t);break;default:a=1}if(a)throw new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[o]+=e,this.f+=e,s===this.u&&(this.isReady()!==this.u&&A("seeded",Math.max(this.o,this.f)),A("progress",this.getProgress()))},isReady:function(t){return t=this.T[void 0!==t?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&(new Date).valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:B(this,this.ma),mouseCollector:B(this,this.oa),keyboardCollector:B(this,this.la),accelerometerCollector:B(this,this.ea),touchCollector:B(this,this.qa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else{if(!document.attachEvent)throw new sjcl.exception.bug("can't attach event");document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)}this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,i=this.K[t],o=[];for(n in i)i.hasOwnProperty(n)&&i[n]===e&&o.push(n);for(r=0;r<o.length;r++)delete i[n=o[r]]},la:function(){C(this,1)},oa:function(t){var e,r;try{e=t.x||t.clientX||t.offsetX||0,r=t.y||t.clientY||t.offsetY||0}catch(t){r=e=0}0!=e&&0!=r&&this.addEntropy([e,r],2,"mouse"),C(this,0)},qa:function(t){t=t.touches[0]||t.changedTouches[0],this.addEntropy([t.pageX||t.clientX,t.pageY||t.clientY],1,"touch"),C(this,0)},ma:function(){C(this,2)},ea:function(t){var e;t=t.accelerationIncludingGravity.x||t.accelerationIncludingGravity.y||t.accelerationIncludingGravity.z,!window.orientation||"number"==typeof(e=window.orientation)&&this.addEntropy(e,1,"accelerometer"),t&&this.addEntropy(t,2,"accelerometer"),C(this,0)}},sjcl.random=new sjcl.prng(6);t:try{if(G="undefined"!=typeof module&&module.exports){try{H=require("crypto")}catch(t){H=null}G=E=H}if(G&&E.randomBytes)D=E.randomBytes(128),D=new Uint32Array(new Uint8Array(D).buffer),sjcl.random.addEntropy(D,1024,"crypto['randomBytes']");else if("undefined"!=typeof window&&"undefined"!=typeof Uint32Array){if(F=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(F);else{if(!window.msCrypto||!window.msCrypto.getRandomValues)break t;window.msCrypto.getRandomValues(F)}sjcl.random.addEntropy(F,1024,"crypto['getRandomValues']")}}catch(t){"undefined"!=typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(t))}sjcl.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var i,o=sjcl.json,s=o.g({iv:sjcl.random.randomWords(4,0)},o.defaults);if(o.g(s,r),r=s.adata,"string"==typeof s.salt&&(s.salt=sjcl.codec.base64.toBits(s.salt)),"string"==typeof s.iv&&(s.iv=sjcl.codec.base64.toBits(s.iv)),!sjcl.mode[s.mode]||!sjcl.cipher[s.cipher]||"string"==typeof t&&s.iter<=100||64!==s.ts&&96!==s.ts&&128!==s.ts||128!==s.ks&&192!==s.ks&&256!==s.ks||s.iv.length<2||4<s.iv.length)throw new sjcl.exception.invalid("json encrypt: invalid parameters");return"string"==typeof t?(t=(i=sjcl.misc.cachedPbkdf2(t,s)).key.slice(0,s.ks/32),s.salt=i.salt):sjcl.ecc&&t instanceof sjcl.ecc.elGamal.publicKey&&(i=t.kem(),s.kemtag=i.tag,t=i.key.slice(0,s.ks/32)),"string"==typeof e&&(e=sjcl.codec.utf8String.toBits(e)),"string"==typeof r&&(s.adata=r=sjcl.codec.utf8String.toBits(r)),i=new sjcl.cipher[s.cipher](t),o.g(n,s),n.key=t,s.ct="ccm"===s.mode&&sjcl.arrayBuffer&&sjcl.arrayBuffer.ccm&&e instanceof ArrayBuffer?sjcl.arrayBuffer.ccm.encrypt(i,e,s.iv,r,s.ts):sjcl.mode[s.mode].encrypt(i,e,s.iv,r,s.ts),s},encrypt:function(t,e,r,n){var i=sjcl.json,o=i.ja.apply(i,arguments);return i.encode(o)},ia:function(t,e,r,n){r=r||{},n=n||{};var i,o=sjcl.json,s=(e=o.g(o.g(o.g({},o.defaults),e),r,!0)).adata;if("string"==typeof e.salt&&(e.salt=sjcl.codec.base64.toBits(e.salt)),"string"==typeof e.iv&&(e.iv=sjcl.codec.base64.toBits(e.iv)),!sjcl.mode[e.mode]||!sjcl.cipher[e.cipher]||"string"==typeof t&&e.iter<=100||64!==e.ts&&96!==e.ts&&128!==e.ts||128!==e.ks&&192!==e.ks&&256!==e.ks||!e.iv||e.iv.length<2||4<e.iv.length)throw new sjcl.exception.invalid("json decrypt: invalid parameters");return"string"==typeof t?(t=(i=sjcl.misc.cachedPbkdf2(t,e)).key.slice(0,e.ks/32),e.salt=i.salt):sjcl.ecc&&t instanceof sjcl.ecc.elGamal.secretKey&&(t=t.unkem(sjcl.codec.base64.toBits(e.kemtag)).slice(0,e.ks/32)),"string"==typeof s&&(s=sjcl.codec.utf8String.toBits(s)),i=new sjcl.cipher[e.cipher](t),s="ccm"===e.mode&&sjcl.arrayBuffer&&sjcl.arrayBuffer.ccm&&e.ct instanceof ArrayBuffer?sjcl.arrayBuffer.ccm.decrypt(i,e.ct,e.iv,e.tag,s,e.ts):sjcl.mode[e.mode].decrypt(i,e.ct,e.iv,s,e.ts),o.g(n,e),n.key=t,1===r.raw?s:sjcl.codec.utf8String.fromBits(s)},decrypt:function(t,e,r,n){var i=sjcl.json;return i.ia(t,i.decode(e),r,n)},encode:function(t){var e,r="{",n="";for(e in t)if(t.hasOwnProperty(e)){if(!e.match(/^[a-z0-9]+$/i))throw new sjcl.exception.invalid("json encode: invalid property name");switch(r+=n+'"'+e+'":',n=",",typeof t[e]){case"number":case"boolean":r+=t[e];break;case"string":r+='"'+escape(t[e])+'"';break;case"object":r+='"'+sjcl.codec.base64.fromBits(t[e],0)+'"';break;default:throw new sjcl.exception.bug("json encode: unsupported type")}}return r+"}"},decode:function(t){if(!(t=t.replace(/\s/g,"")).match(/^\{.*\}$/))throw new sjcl.exception.invalid("json decode: this isn't json!");t=t.replace(/^\{|\}$/g,"").split(/,/);for(var e,r={},n=0;n<t.length;n++){if(!(e=t[n].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i)))throw new sjcl.exception.invalid("json decode: this isn't json!");null!=e[3]?r[e[2]]=parseInt(e[3],10):null!=e[4]?r[e[2]]=e[2].match(/^(ct|adata|salt|iv)$/)?sjcl.codec.base64.toBits(e[4]):unescape(e[4]):null!=e[5]&&(r[e[2]]="true"===e[5])}return r},g:function(t,e,r){if(void 0===t&&(t={}),void 0===e)return t;for(var n in e)if(e.hasOwnProperty(n)){if(r&&void 0!==t[n]&&t[n]!==e[n])throw new sjcl.exception.invalid("required parameter overridden");t[n]=e[n]}return t},sa:function(t,e){var r,n={};for(r in t)t.hasOwnProperty(r)&&t[r]!==e[r]&&(n[r]=t[r]);return n},ra:function(t,e){for(var r={},n=0;n<e.length;n++)void 0!==t[e[n]]&&(r[e[n]]=t[e[n]]);return r}},sjcl.encrypt=sjcl.json.encrypt,sjcl.decrypt=sjcl.json.decrypt,sjcl.misc.pa={},sjcl.misc.cachedPbkdf2=function(t,e){var r=sjcl.misc.pa,n=(e=e||{}).iter||1e3;return(n=(r=r[t]=r[t]||{})[n]=r[n]||{firstSalt:e.salt&&e.salt.length?e.salt.slice(0):sjcl.random.randomWords(2,0)})[r=void 0===e.salt?n.firstSalt:e.salt]=n[r]||sjcl.misc.pbkdf2(t,r,e.iter),{key:n[r].slice(0),salt:r.slice(0)}},"undefined"!=typeof module&&module.exports&&(module.exports=sjcl),"function"==typeof define&&define([],function(){return sjcl}),sjcl.bitArray={bitSlice:function(t,e,r){return t=sjcl.bitArray._shiftRight(t.slice(e/32),32-(31&e)).slice(1),void 0===r?t:sjcl.bitArray.clamp(t,r-e)},extract:function(t,e,r){var n=Math.floor(-e-r&31);return(-32&(e+r-1^e)?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n)&(1<<r)-1},concat:function(t,e){if(0===t.length||0===e.length)return t.concat(e);var r=t[t.length-1],n=sjcl.bitArray.getPartial(r);return 32===n?t.concat(e):sjcl.bitArray._shiftRight(e,n,0|r,t.slice(0,t.length-1))},bitLength:function(t){var e,r=t.length;return 0===r?0:(e=t[r-1],32*(r-1)+sjcl.bitArray.getPartial(e))},clamp:function(t,e){if(32*t.length<e)return t;var r=(t=t.slice(0,Math.ceil(e/32))).length;return e&=31,0<r&&e&&(t[r-1]=sjcl.bitArray.partial(e,t[r-1]&2147483648>>e-1,1)),t},partial:function(t,e,r){return 32===t?e:(r?0|e:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(sjcl.bitArray.bitLength(t)!==sjcl.bitArray.bitLength(e))return!1;for(var r=0,n=0;n<t.length;n++)r|=t[n]^e[n];return 0===r},_shiftRight:function(t,e,r,n){var i,o,s;for(void 0===n&&(n=[]);32<=e;e-=32)n.push(r),r=0;if(0===e)return n.concat(t);for(i=0;i<t.length;i++)n.push(r|t[i]>>>e),r=t[i]<<32-e;return o=t.length?t[t.length-1]:0,s=sjcl.bitArray.getPartial(o),n.push(sjcl.bitArray.partial(e+s&31,32<e+s?r:n.pop(),1)),n},_xor4:function(t,e){return[t[0]^e[0],t[1]^e[1],t[2]^e[2],t[3]^e[3]]},byteswapM:function(t){for(var e,r=0;r<t.length;++r)e=t[r],t[r]=e>>>24|e>>>8&65280|(65280&e)<<8|e<<24;return t}},sjcl.misc.hkdf=function(t,e,r,n,i){var o,s,a,c,l,u,h=[];if(i=i||sjcl.hash.sha256,"string"==typeof n&&(n=sjcl.codec.utf8String.toBits(n)),r="string"==typeof r?sjcl.codec.utf8String.toBits(r):r||[],s=(o=new sjcl.misc.hmac(r,i)).mac(t),c=sjcl.bitArray.bitLength(s),255<(l=Math.ceil(e/c)))throw new sjcl.exception.invalid("key bit length is too large for hkdf");for(o=new sjcl.misc.hmac(s,i),u=[],a=1;a<=l;a++)o.update(u),o.update(n),o.update([sjcl.bitArray.partial(8,a)]),u=o.digest(),h=sjcl.bitArray.concat(h,u);return sjcl.bitArray.clamp(h,e)};