(function(a){a.jCryption=function(c,b){var d=this;d.$el=a(c);d.el=c;d.$el.data("jCryption",d);d.$el.data("salt",null);d.$el.data("key",null);d.init=function(){d.options=a.extend({},a.jCryption.defaultOptions,b);d.$el.bind("mousemove",function(a){null===d.$el.data("salt")?d.$el.data("salt",(a.pageX+a.pageY)*Math.random()):d.$el.unbind("mousemove")});$encryptedElement=a("",{type:"hidden",name:d.options.postVariable});var c=!1!==d.options.submitElement?d.options.submitElement:d.$el.find(":input:submit");c.bind(d.options.submitEvent,function(){a(this).attr("disabled",!0);d.options.beforeEncryption()&&d.authenticate(function(b){var g=d.$el.serialize();c.is(":submit")&&(g=g+"&"+c.attr("name")+"="+c.val());$encryptedElement.val(a.jCryption.encrypt(g,b));a(d.$el).find(d.options.formFieldSelector).attr("disabled",!0).end().append($encryptedElement).submit()},function(){a(d.$el).submit()});return!1})};d.init();d.getKey=function(){if(null!==d.$el.data("key"))return d.$el.data("key");var a=d.$el.data("salt");null===a&&(a=Math.floor(Math.random()*Math.random()));a=new jsSHA(a.toString(),"ASCII");d.$el.data("key",a.getHash("SHA-512","HEX"));return d.getKey()};d.authenticate=function(b,c){var g=d.getKey();a.jCryption.authenticate(g,d.options.getKeysURL,d.options.handshakeURL,b,c)}};a.jCryption.authenticate=function(c,b,d,e,f){a.jCryption.getKeys(b,function(b){a.jCryption.encryptKey(c,b,function(b){a.jCryption.handshake(d,b,function(b){a.jCryption.challenge(b.challenge,c)?e.call(this,c):f.call(this)})})})};a.jCryption.getKeys=function(c,b){var d=function(a,b,c){setMaxDigits(parseInt(c,10));this.e=biFromHex(a);this.m=biFromHex(b);this.chunkSize=2*biHighIndex(this.m);this.radix=16;this.barrett=new BarrettMu(this.m)};a.getJSON(c,function(c){c=new d(c.e,c.n,c.maxdigits);a.isFunction(b)&&b.call(this,c)})};a.jCryption.decrypt=function(a,b){return Aes.Ctr.decrypt(a,b,256)};a.jCryption.encrypt=function(a,b){return Aes.Ctr.encrypt(a,b,256)};a.jCryption.challenge=function(c,b){return a.jCryption.decrypt(c,b)==b?!0:!1};a.jCryption.handshake=function(c,b,d){a.ajax({url:c,dataType:"json",type:"POST",data:{key:b},success:function(a){d.call(this,a)}})};a.jCryption.encryptKey=function(c,b,d){for(var e=0,f=0;f>4)+"0123456789abcdef".charAt(e&15));c=e+c;e=[];for(f=0;f>>1,biRadixSquared=biRadix*biRadix,maxDigitVal=biRadix-1,maxInteger=9999999999999998,maxDigits,ZERO_ARRAY,bigZero,bigOne,dpl10=15,highBitMasks=[0,32768,49152,57344,61440,63488,64512,65024,65280,65408,65472,65504,65520,65528,65532,65534,65535],hexatrigesimalToChar="0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(","),hexToChar="0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f".split(","),lowBitMasks=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function setMaxDigits(a){maxDigits=a;ZERO_ARRAY=Array(maxDigits);for(a=0;aa;for(var a=Math.abs(a),b=0;0>=biRadixBits;return c}function reverseStr(a){for(var c="",b=a.length-1;-1i;++i)c+=hexToChar[a&15],a>>>=4;return reverseStr(c)}function biToHex(a){var c="";biHighIndex(a);for(var b=biHighIndex(a);-1=a?a-48:65<=a&&90>=a?10+a-65:97<=a&&122>=a?10+a-97:0}function hexToDigit(a){for(var c=0,b=Math.min(a.length,4),d=0;d=d;g--)var l=a.charCodeAt(g),l=charToHex(l),l=biMultiplyDigit(f,l),e=biAdd(e,l),f=biMultiplyDigit(f,c);e.isNeg=b;return e}function biDump(a){return(a.isNeg?"-":"")+a.digits.join(" ")}function biAdd(a,c){var b;if(a.isNeg!=c.isNeg)c.isNeg=!c.isNeg,b=biSubtract(a,c),c.isNeg=!c.isNeg;else{b=new BigInt;for(var d=0,e=0;e=biRadix);b.isNeg=a.isNeg}return b}function biSubtract(a,c){var b;if(a.isNeg!=c.isNeg)c.isNeg=!c.isNeg,b=biAdd(a,c),c.isNeg=!c.isNeg;else{b=new BigInt;for(var d,e=d=0;eb.digits[e]&&(b.digits[e]+=biRadix),d=0-Number(0>d);if(-1==d){for(e=d=0;eb.digits[e]&&(b.digits[e]+=biRadix),d=0-Number(0>d);b.isNeg=!a.isNeg}else b.isNeg=a.isNeg}return b}function biHighIndex(a){for(var c=a.digits.length-1;0c-bitsPerDigit&&!(0!=(a&32768));--b)a<<=1;return b}function biMultiply(a,c){for(var b=new BigInt,d,e=biHighIndex(a),f=biHighIndex(c),g,l=0;l<=f;++l){d=0;g=l;for(j=0;j<=e;++j,++g)d=b.digits[g]+a.digits[j]*c.digits[l]+d,b.digits[g]=d&maxDigitVal,d>>>=biRadixBits;b.digits[l+e+1]=d}b.isNeg=a.isNeg!=c.isNeg;return b}function biMultiplyDigit(a,c){var b,d,e=new BigInt;b=biHighIndex(a);for(var f=d=0;f<=b;++f)d=e.digits[f]+a.digits[f]*c+d,e.digits[f]=d&maxDigitVal,d>>>=biRadixBits;e.digits[1+b]=d;return e}function arrayCopy(a,c,b,d,e){for(e=Math.min(c+e,a.length);c>>e;d.digits[0]=d.digits[f]<>>b|(d.digits[g]&lowBitMasks[b])<>>=b;d.isNeg=a.isNeg;return d}function biMultiplyByRadixPower(a,c){var b=new BigInt;arrayCopy(a.digits,0,b.digits,c,b.digits.length-c);return b}function biDivideByRadixPower(a,c){var b=new BigInt;arrayCopy(a.digits,c,b.digits,0,b.digits.length-c);return b}function biModuloByRadixPower(a,c){var b=new BigInt;arrayCopy(a.digits,0,b.digits,0,c);return b}function biCompare(a,c){if(a.isNeg!=c.isNeg)return 1-2*Number(a.isNeg);for(var b=a.digits.length-1;0<=b;--b)if(a.digits[b]!=c.digits[b])return a.isNeg?1-2*Number(a.digits[b]>c.digits[b]):1-2*Number(a.digits[b]l;--b){var d=b>=g.digits.length?0:g.digits[b],n=b-1>=g.digits.length?0:g.digits[b-1],p=b-2>=g.digits.length?0:g.digits[b-2],s=l>=c.digits.length?0:c.digits[l],k=l-1>=c.digits.length?0:c.digits[l-1];f.digits[b-l-1]=d==s?maxDigitVal:Math.floor((d*biRadix+n)/s);for(var t=f.digits[b-l-1]*(s*biRadix+k),r=d*biRadixSquared+(n*biRadix+p);t>r;)--f.digits[b-l-1],t=f.digits[b-l-1]*(s*biRadix|k),r=d*biRadix*biRadix+(n*biRadix+p);d=biMultiplyByRadixPower(c,b-l-1);g=biSubtract(g,biMultiplyDigit(d,f.digits[b-l-1]));g.isNeg&&(g=biAdd(g,d),--f.digits[b-l-1])}g=biShiftRight(g,m);f.isNeg=a.isNeg!=e;a.isNeg&&(f=e?biAdd(f,bigOne):biSubtract(f,bigOne),c=biShiftRight(c,m),g=biSubtract(c,g));if(0==g.digits[0]&&0==biHighIndex(g))g.isNeg=!1;return[f,g]}function biDivide(a,c){return biDivideModulo(a,c)[0]}function biModulo(a,c){return biDivideModulo(a,c)[1]}function biMultiplyMod(a,c,b){return biModulo(biMultiply(a,c),b)}function biPow(a,c){for(var b=bigOne,d=a;;){0!=(c&1)&&(b=biMultiply(b,d));c>>=1;if(0==c)break;d=biMultiply(d,d)}return b}function biPowMod(a,c,b){for(var d=bigOne;;){0!=(c.digits[0]&1)&&(d=biMultiplyMod(d,a,b));c=biShiftRight(c,1);if(0==c.digits[0]&&0==biHighIndex(c))break;a=biMultiplyMod(a,a,b)}return d}function BarrettMu(a){this.modulus=biCopy(a);this.k=biHighIndex(this.modulus)+1;a=new BigInt;a.digits[2*this.k]=1;this.mu=biDivide(a,this.modulus);this.bkplus1=new BigInt;this.bkplus1.digits[this.k+1]=1;this.modulo=BarrettMu_modulo;this.multiplyMod=BarrettMu_multiplyMod;this.powMod=BarrettMu_powMod}function BarrettMu_modulo(a){var c=biDivideByRadixPower(a,this.k-1),c=biMultiply(c,this.mu),c=biDivideByRadixPower(c,this.k+1),a=biModuloByRadixPower(a,this.k+1),c=biMultiply(c,this.modulus),c=biModuloByRadixPower(c,this.k+1),a=biSubtract(a,c);a.isNeg&&(a=biAdd(a,this.bkplus1));for(c=0<=biCompare(a,this.modulus);c;)a=biSubtract(a,this.modulus),c=0<=biCompare(a,this.modulus);return a}function BarrettMu_multiplyMod(a,c){return this.modulo(biMultiply(a,c))}function BarrettMu_powMod(a,c){var b=new BigInt;for(b.digits[0]=1;;){0!=(c.digits[0]&1)&&(b=this.multiplyMod(b,a));c=biShiftRight(c,1);if(0==c.digits[0]&&0==biHighIndex(c))break;a=this.multiplyMod(a,a)}return b}var Aes={};Aes.cipher=function(a,c){for(var b=c.length/4-1,d=[[],[],[],[]],e=0;16>e;e++)d[e%4][Math.floor(e/4)]=a[e];d=Aes.addRoundKey(d,c,0,4);for(e=1;ee;e++)b[e]=d[e%4][Math.floor(e/4)];return b};Aes.keyExpansion=function(a){for(var c=a.length/4,b=c+6,d=Array(4*(b+1)),e=Array(4),f=0;fa;a++)e[a]=d[f-1][a];if(0==f%c){e=Aes.subWord(Aes.rotWord(e));for(a=0;4>a;a++)e[a]^=Aes.rCon[f/c][a]}else 6a;a++)d[f][a]=d[f-c][a]^e[a]}return d};Aes.subBytes=function(a,c){for(var b=0;4>b;b++)for(var d=0;dd;d++){for(var e=0;4>e;e++)b[e]=a[d][(e+d)%c];for(e=0;4>e;e++)a[d][e]=b[e]}return a};Aes.mixColumns=function(a){for(var c=0;4>c;c++){for(var b=Array(4),d=Array(4),e=0;4>e;e++)b[e]=a[e][c],d[e]=a[e][c]&128?a[e][c]<<1^283:a[e][c]<<1;a[0][c]=d[0]^b[1]^d[1]^b[2]^b[3];a[1][c]=b[0]^d[1]^b[2]^d[2]^b[3];a[2][c]=b[0]^b[1]^d[2]^b[3]^d[3];a[3][c]=b[0]^d[0]^b[1]^b[2]^d[3]}return a};Aes.addRoundKey=function(a,c,b,d){for(var e=0;4>e;e++)for(var f=0;fc;c++)a[c]=Aes.sBox[a[c]];return a};Aes.rotWord=function(a){for(var c=a[0],b=0;3>b;b++)a[b]=a[b+1];a[3]=c;return a};Aes.sBox=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22];Aes.rCon=[[0,0,0,0],[1,0,0,0],[2,0,0,0],[4,0,0,0],[8,0,0,0],[16,0,0,0],[32,0,0,0],[64,0,0,0],[128,0,0,0],[27,0,0,0],[54,0,0,0]];Aes.Ctr={};Aes.Ctr.encrypt=function(a,c,b){if(!(128==b||192==b||256==b))return"";for(var a=Utf8.encode(a),c=Utf8.encode(c),d=b/8,e=Array(d),b=0;bb;b++)c[b]=d>>>8*b&255;for(b=0;2>b;b++)c[b+2]=g>>>8*b&255;for(b=0;4>b;b++)c[b+4]=f>>>8*b&255;d="";for(b=0;8>b;b++)d+=String.fromCharCode(c[b]);for(var e=Aes.keyExpansion(e),f=Math.ceil(a.length/16),g=Array(f),l=0;lb;b++)c[15-b]=l>>>8*b&255;for(b=0;4>b;b++)c[15-b-4]=l/4294967296>>>8*b;for(var m=Aes.cipher(c,e),n=lb;b++)c[b]=ctrTxt.charCodeAt(b);for(var d=Aes.keyExpansion(e),e=Math.ceil((a.length-8)/16),b=Array(e),f=0;fb;b++)c[15-b]=f>>>8*b&255;for(b=0;4>b;b++)c[15-b-4]=(f+1)/4294967296-1>>>8*b&255;for(var l=Aes.cipher(c,d),m=Array(a[f].length),b=0;bm++;)l+="=",n+="\x00";for(m=0;m>18&63,d=f>>12&63,e=f>>6&63,f&=63,g[m/3]=p.charAt(b)+p.charAt(d)+p.charAt(e)+p.charAt(f);g=g.join("");return g=g.slice(0,g.length-l.length)+l},decode:function(a,c){var c="undefined"==typeof c?!1:c,b,d,e,f,g,l=[],m,n=Base64.code;m=c?a.decodeUTF8():a;for(var p=0;p>>16&255,d=e>>>8&255,e&=255,l[p/4]=String.fromCharCode(b,d,e),64==g&&(l[p/4]=String.fromCharCode(b,d)),64==f&&(l[p/4]=String.fromCharCode(b));f=l.join("");return c?f.decodeUTF8():f}},Utf8={encode:function(a){a=a.replace(/[\u0080-\u07ff]/g,function(a){a=a.charCodeAt(0);return String.fromCharCode(192|a>>6,128|a&63)});return a=a.replace(/[\u0800-\uffff]/g,function(a){a=a.charCodeAt(0);return String.fromCharCode(224|a>>12,128|a>>6&63,128|a&63)})},decode:function(a){a=a.replace(/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g,function(a){a=(a.charCodeAt(0)&15)<<12|(a.charCodeAt(1)&63)<<6|a.charCodeAt(2)&63;return String.fromCharCode(a)});return a=a.replace(/[\u00c0-\u00df][\u0080-\u00bf]/g,function(a){a=(a.charCodeAt(0)&31)<<6|a.charCodeAt(1)&63;return String.fromCharCode(a)})}},charSize=8,b64pad="",hexCase=0,Int_64=function(a,c){this.highOrder=a;this.lowOrder=c},str2binb=function(a){var c=[],b=(1<>5]|=(a.charCodeAt(e/charSize)&b)<<32-charSize-e%32;return c},hex2binb=function(a){var c=[],b=a.length,d,e;for(d=0;d>3]|=e<<24-4*(d%8)}return c},binb2hex=function(a){var c=hexCase?"0123456789ABCDEF":"0123456789abcdef",b="",d=4*a.length,e,f;for(e=0;e>2]>>8*(3-e%4),b+=c.charAt(f>>4&15)+c.charAt(f&15);return b},binb2b64=function(a){var c="",b=4*a.length,d,e,f;for(d=0;d>2]>>8*(3-d%4)&255)<<16|(a[d+1>>2]>>8*(3-(d+1)%4)&255)<<8|a[d+2>>2]>>8*(3-(d+2)%4)&255;for(e=0;4>e;e+=1)c=8*d+6*e<=32*a.length?c+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f>>6*(3-e)&63):c+b64pad}return c},rotl_32=function(a,c){return a<>>32-c},rotr_32=function(a,c){return a>>>c|a<<32-c},rotr_64=function(a,c){return 32>=c?new Int_64(a.highOrder>>>c|a.lowOrder<<32-c,a.lowOrder>>>c|a.highOrder<<32-c):new Int_64(a.lowOrder>>>c|a.highOrder<<32-c,a.highOrder>>>c|a.lowOrder<<32-c)},shr_32=function(a,c){return a>>>c},shr_64=function(a,c){return 32>=c?new Int_64(a.highOrder>>>c,a.lowOrder>>>c|a.highOrder<<32-c):new Int_64(0,a.highOrder<<32-c)},parity_32=function(a,c,b){return a^c^b},ch_32=function(a,c,b){return a&c^~a&b},ch_64=function(a,c,b){return new Int_64(a.highOrder&c.highOrder^~a.highOrder&b.highOrder,a.lowOrder&c.lowOrder^~a.lowOrder&b.lowOrder)},maj_32=function(a,c,b){return a&c^a&b^c&b},maj_64=function(a,c,b){return new Int_64(a.highOrder&c.highOrder^a.highOrder&b.highOrder^c.highOrder&b.highOrder,a.lowOrder&c.lowOrder^a.lowOrder&b.lowOrder^c.lowOrder&b.lowOrder)},sigma0_32=function(a){return rotr_32(a,2)^rotr_32(a,13)^rotr_32(a,22)},sigma0_64=function(a){var c=rotr_64(a,28),b=rotr_64(a,34),a=rotr_64(a,39);return new Int_64(c.highOrder^b.highOrder^a.highOrder,c.lowOrder^b.lowOrder^a.lowOrder)},sigma1_32=function(a){return rotr_32(a,6)^rotr_32(a,11)^rotr_32(a,25)},sigma1_64=function(a){var c=rotr_64(a,14),b=rotr_64(a,18),a=rotr_64(a,41);return new Int_64(c.highOrder^b.highOrder^a.highOrder,c.lowOrder^b.lowOrder^a.lowOrder)},gamma0_32=function(a){return rotr_32(a,7)^rotr_32(a,18)^shr_32(a,3)},gamma0_64=function(a){var c=rotr_64(a,1),b=rotr_64(a,8),a=shr_64(a,7);return new Int_64(c.highOrder^b.highOrder^a.highOrder,c.lowOrder^b.lowOrder^a.lowOrder)},gamma1_32=function(a){return rotr_32(a,17)^rotr_32(a,19)^shr_32(a,10)},gamma1_64=function(a){var c=rotr_64(a,19),b=rotr_64(a,61),a=shr_64(a,6);return new Int_64(c.highOrder^b.highOrder^a.highOrder,c.lowOrder^b.lowOrder^a.lowOrder)},safeAdd_32_2=function(a,c){var b=(a&65535)+(c&65535);return((a>>>16)+(c>>>16)+(b>>>16)&65535)<<16|b&65535},safeAdd_32_4=function(a,c,b,d){var e=(a&65535)+(c&65535)+(b&65535)+(d&65535);return((a>>>16)+(c>>>16)+(b>>>16)+(d>>>16)+(e>>>16)&65535)<<16|e&65535},safeAdd_32_5=function(a,c,b,d,e){var f=(a&65535)+(c&65535)+(b&65535)+(d&65535)+(e&65535);return((a>>>16)+(c>>>16)+(b>>>16)+(d>>>16)+(e>>>16)+(f>>>16)&65535)<<16|f&65535},safeAdd_64_2=function(a,c){var b,d,e;b=(a.lowOrder&65535)+(c.lowOrder&65535);d=(a.lowOrder>>>16)+(c.lowOrder>>>16)+(b>>>16);e=(d&65535)<<16|b&65535;b=(a.highOrder&65535)+(c.highOrder&65535)+(d>>>16);d=(a.highOrder>>>16)+(c.highOrder>>>16)+(b>>>16);return new Int_64((d&65535)<<16|b&65535,e)},safeAdd_64_4=function(a,c,b,d){var e,f,g;e=(a.lowOrder&65535)+(c.lowOrder&65535)+(b.lowOrder&65535)+(d.lowOrder&65535);f=(a.lowOrder>>>16)+(c.lowOrder>>>16)+(b.lowOrder>>>16)+(d.lowOrder>>>16)+(e>>>16);g=(f&65535)<<16|e&65535;e=(a.highOrder&65535)+(c.highOrder&65535)+(b.highOrder&65535)+(d.highOrder&65535)+(f>>>16);f=(a.highOrder>>>16)+(c.highOrder>>>16)+(b.highOrder>>>16)+(d.highOrder>>>16)+(e>>>16);return new Int_64((f&65535)<<16|e&65535,g)},safeAdd_64_5=function(a,c,b,d,e){var f,g,l;f=(a.lowOrder&65535)+(c.lowOrder&65535)+(b.lowOrder&65535)+(d.lowOrder&65535)+(e.lowOrder&65535);g=(a.lowOrder>>>16)+(c.lowOrder>>>16)+(b.lowOrder>>>16)+(d.lowOrder>>>16)+(e.lowOrder>>>16)+(f>>>16);l=(g&65535)<<16|f&65535;f=(a.highOrder&65535)+(c.highOrder&65535)+(b.highOrder&65535)+(d.highOrder&65535)+(e.highOrder&65535)+(g>>>16);g=(a.highOrder>>>16)+(c.highOrder>>>16)+(b.highOrder>>>16)+(d.highOrder>>>16)+(e.highOrder>>>16)+(f>>>16);return new Int_64((g&65535)<<16|f&65535,l)},coreSHA1=function(a,c){var b=[],d,e,f,g,l,m,n=ch_32,p=parity_32,s=maj_32,k=rotl_32,t=safeAdd_32_2,r,o,u=safeAdd_32_5,w,q=[1732584193,4023233417,2562383102,271733878,3285377520],v=[1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782];a[c>>5]|=128<<24-c%32;a[(c+65>>9<<4)+15]=c;w=a.length;for(r=0;ro;o+=1)b[o]=16>o?a[o+r]:k(b[o-3]^b[o-8]^b[o-14]^b[o-16],1),m=20>o?u(k(d,5),n(e,f,g),l,v[o],b[o]):40>o?u(k(d,5),p(e,f,g),l,v[o],b[o]):60>o?u(k(d,5),s(e,f,g),l,v[o],b[o]):u(k(d,5),p(e,f,g),l,v[o],b[o]),l=g,g=f,f=k(e,30),e=d,d=m;q[0]=t(d,q[0]);q[1]=t(e,q[1]);q[2]=t(f,q[2]);q[3]=t(g,q[3]);q[4]=t(l,q[4])}return q},coreSHA2=function(a,c,b){var d,e,f,g,l,m,n,p,s,k,t,r,o,u,w,q,v,y,z,A,B,C,D,E,h,F,x=[],G;if("SHA-224"===b||"SHA-256"===b)t=64,d=(c+65>>9<<4)+15,u=16,w=1,h=Number,q=safeAdd_32_2,v=safeAdd_32_4,y=safeAdd_32_5,z=gamma0_32,A=gamma1_32,B=sigma0_32,C=sigma1_32,E=maj_32,D=ch_32,F=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],k="SHA-224"===b?[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]:[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];else if("SHA-384"===b||"SHA-512"===b)t=80,d=(c+128>>10<<5)+31,u=32,w=2,h=Int_64,q=safeAdd_64_2,v=safeAdd_64_4,y=safeAdd_64_5,z=gamma0_64,A=gamma1_64,B=sigma0_64,C=sigma1_64,E=maj_64,D=ch_64,F=[new h(1116352408,3609767458),new h(1899447441,602891725),new h(3049323471,3964484399),new h(3921009573,2173295548),new h(961987163,4081628472),new h(1508970993,3053834265),new h(2453635748,2937671579),new h(2870763221,3664609560),new h(3624381080,2734883394),new h(310598401,1164996542),new h(607225278,1323610764),new h(1426881987,3590304994),new h(1925078388,4068182383),new h(2162078206,991336113),new h(2614888103,633803317),new h(3248222580,3479774868),new h(3835390401,2666613458),new h(4022224774,944711139),new h(264347078,2341262773),new h(604807628,2007800933),new h(770255983,1495990901),new h(1249150122,1856431235),new h(1555081692,3175218132),new h(1996064986,2198950837),new h(2554220882,3999719339),new h(2821834349,766784016),new h(2952996808,2566594879),new h(3210313671,3203337956),new h(3336571891,1034457026),new h(3584528711,2466948901),new h(113926993,3758326383),new h(338241895,168717936),new h(666307205,1188179964),new h(773529912,1546045734),new h(1294757372,1522805485),new h(1396182291,2643833823),new h(1695183700,2343527390),new h(1986661051,1014477480),new h(2177026350,1206759142),new h(2456956037,344077627),new h(2730485921,1290863460),new h(2820302411,3158454273),new h(3259730800,3505952657),new h(3345764771,106217008),new h(3516065817,3606008344),new h(3600352804,1432725776),new h(4094571909,1467031594),new h(275423344,851169720),new h(430227734,3100823752),new h(506948616,1363258195),new h(659060556,3750685593),new h(883997877,3785050280),new h(958139571,3318307427),new h(1322822218,3812723403),new h(1537002063,2003034995),new h(1747873779,3602036899),new h(1955562222,1575990012),new h(2024104815,1125592928),new h(2227730452,2716904306),new h(2361852424,442776044),new h(2428436474,593698344),new h(2756734187,3733110249),new h(3204031479,2999351573),new h(3329325298,3815920427),new h(3391569614,3928383900),new h(3515267271,566280711),new h(3940187606,3454069534),new h(4118630271,4000239992),new h(116418474,1914138554),new h(174292421,2731055270),new h(289380356,3203993006),new h(460393269,320620315),new h(685471733,587496836),new h(852142971,1086792851),new h(1017036298,365543100),new h(1126000580,2618297676),new h(1288033470,3409855158),new h(1501505948,4234509866),new h(1607167915,987167468),new h(1816402316,1246189591)],k="SHA-384"===b?[new h(3418070365,3238371032),new h(1654270250,914150663),new h(2438529370,812702999),new h(355462360,4144912697),new h(1731405415,4290775857),new h(41048885895,1750603025),new h(3675008525,1694076839),new h(1203062813,3204075428)]:[new h(1779033703,4089235720),new h(3144134277,2227873595),new h(1013904242,4271175723),new h(2773480762,1595750129),new h(1359893119,2917565137),new h(2600822924,725511199),new h(528734635,4215389547),new h(1541459225,327033209)];a[c>>5]|=128<<24-c%32;a[d]=c;G=a.length;for(r=0;ro?new h(a[o*w+r],a[o*w+r+1]):v(A(x[o-2]),x[o-7],z(x[o-15]),x[o-16]),p=y(n,C(g),D(g,l,m),F[o],x[o]),s=q(B(c),E(c,d,e)),n=m,m=l,l=g,g=q(f,p),f=e,e=d,d=c,c=q(p,s);k[0]=q(c,k[0]);k[1]=q(d,k[1]);k[2]=q(e,k[2]);k[3]=q(f,k[3]);k[4]=q(g,k[4]);k[5]=q(l,k[5]);k[6]=q(m,k[6]);k[7]=q(n,k[7])}switch(b){case "SHA-224":return[k[0],k[1],k[2],k[3],k[4],k[5],k[6]];case "SHA-256":return k;case "SHA-384":return[k[0].highOrder,k[0].lowOrder,k[1].highOrder,k[1].lowOrder,k[2].highOrder,k[2].lowOrder,k[3].highOrder,k[3].lowOrder,k[4].highOrder,k[4].lowOrder,k[5].highOrder,k[5].lowOrder];case "SHA-512":return[k[0].highOrder,k[0].lowOrder,k[1].highOrder,k[1].lowOrder,k[2].highOrder,k[2].lowOrder,k[3].highOrder,k[3].lowOrder,k[4].highOrder,k[4].lowOrder,k[5].highOrder,k[5].lowOrder,k[6].highOrder,k[6].lowOrder,k[7].highOrder,k[7].lowOrder];default:return[]}},jsSHA=function(a,c){this.strToHash=this.strBinLen=this.sha512=this.sha384=this.sha256=this.sha224=this.sha1=null;if("HEX"===c){if(0!==a.length%2)return"TEXT MUST BE IN BYTE INCREMENTS";this.strBinLen=4*a.length;this.strToHash=hex2binb(a)}else if("ASCII"===c||"undefined"===typeof c)this.strBinLen=a.length*charSize,this.strToHash=str2binb(a);else return"UNKNOWN TEXT INPUT TYPE"};jsSHA.prototype={getHash:function(a,c){var b=null,d=this.strToHash.slice();switch(c){case "HEX":b=binb2hex;break;case "B64":b=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}switch(a){case "SHA-1":if(null===this.sha1)this.sha1=coreSHA1(d,this.strBinLen);return b(this.sha1);case "SHA-224":if(null===this.sha224)this.sha224=coreSHA2(d,this.strBinLen,a);return b(this.sha224);case "SHA-256":if(null===this.sha256)this.sha256=coreSHA2(d,this.strBinLen,a);return b(this.sha256);case "SHA-384":if(null===this.sha384)this.sha384=coreSHA2(d,this.strBinLen,a);return b(this.sha384);case "SHA-512":if(null===this.sha512)this.sha512=coreSHA2(d,this.strBinLen,a);return b(this.sha512);default:return"HASH NOT RECOGNIZED"}},getHMAC:function(a,c,b,d){var e,f,g,l,m;f=[];var n=[];switch(d){case "HEX":d=binb2hex;break;case "B64":d=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}switch(b){case "SHA-1":e=64;m=160;break;case "SHA-224":e=64;m=224;break;case "SHA-256":e=64;m=256;break;case "SHA-384":e=128;m=384;break;case "SHA-512":e=128;m=512;break;default:return"HASH NOT RECOGNIZED"}if("HEX"===c){if(0!==a.length%2)return"KEY MUST BE IN BYTE INCREMENTS";c=hex2binb(a);l=4*a.length}else if("ASCII"===c)c=str2binb(a),l=a.length*charSize;else return"UNKNOWN KEY INPUT TYPE";a=8*e;g=e/4-1;el/8&&(c[g]&=4294967040);for(e=0;e<=g;e+=1)f[e]=c[e]^909522486,n[e]=c[e]^1549556828;"SHA-1"===b?(f=coreSHA1(f.concat(this.strToHash),a+this.strBinLen),f=coreSHA1(n.concat(f),a+m)):(f=coreSHA2(f.concat(this.strToHash),a+this.strBinLen,b),f=coreSHA2(n.concat(f),a+m,b));return d(f)}};window.jsSHA=jsSHA;