bdcontract-sdk-javascript/test/cryptico.iife.js

3 lines
36 KiB
JavaScript
Raw Normal View History

2023-03-14 17:15:57 +00:00
var cryptico=function(t,s){"use strict";function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=e(s);!function(){const t={};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,t)}catch(t){}globalThis.process={env:t}}();const r={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],ShiftRowTab:[0,5,10,15,4,9,14,3,8,13,2,7,12,1,6,11],Sbox_Inv:new Array(256),ShiftRowTab_Inv:new Array(16),xtime:new Array(256),Init(){for(let t=0;t<256;t++)this.Sbox_Inv[this.Sbox[t]]=t;for(let t=0;t<16;t++)this.ShiftRowTab_Inv[this.ShiftRowTab[t]]=t;for(let t=0;t<128;t++)this.xtime[t]=t<<1,this.xtime[128+t]=t<<1^27},Done(){this.Sbox_Inv.length=0,this.Sbox_Inv.length=256,this.ShiftRowTab_Inv.length=0,this.ShiftRowTab_Inv.length=16,this.xtime.length=0,this.xtime.length=256},ExpandKey(t){const s=t.length;let e,i=1;switch(s){case 16:e=176;break;case 24:e=208;break;case 32:e=240;break;default:throw"my.ExpandKey: Only key lengths of 16, 24 or 32 bytes allowed!"}for(let n=s;n<e;n+=4){let e=t.slice(n-4,n);n%s==0?(e=[r.Sbox[e[1]]^i,r.Sbox[e[2]],r.Sbox[e[3]],r.Sbox[e[0]]],(i<<=1)>=256&&(i^=283)):s>24&&n%s==16&&(e=[r.Sbox[e[0]],r.Sbox[e[1]],r.Sbox[e[2]],r.Sbox[e[3]]]);for(let i=0;i<4;i++)t[n+i]=t[n+i-s]^e[i]}},Encrypt(t,s){const e=s.length;let i;for(r.AddRoundKey(t,s.slice(0,16)),i=16;i<e-16;i+=16)r.SubBytes(t,r.Sbox),r.ShiftRows(t,r.ShiftRowTab),r.MixColumns(t),r.AddRoundKey(t,s.slice(i,i+16));r.SubBytes(t,r.Sbox),r.ShiftRows(t,r.ShiftRowTab),r.AddRoundKey(t,s.slice(i,e))},Decrypt(t,s){const e=s.length;r.AddRoundKey(t,s.slice(e-16,e)),r.ShiftRows(t,r.ShiftRowTab_Inv),r.SubBytes(t,r.Sbox_Inv);for(let i=e-32;i>=16;i-=16)r.AddRoundKey(t,s.slice(i,i+16)),r.MixColumns_Inv(t),r.ShiftRows(t,r.ShiftRowTab_Inv),r.SubBytes(t,r.Sbox_Inv);r.AddRoundKey(t,s.slice(0,16))},SubBytes(t,s){for(let e=0;e<16;e++)t[e]=s[t[e]]},AddRoundKey(t,s){for(let e=0;e<16;e++)t[e]^=s[e]},ShiftRows(t,s){const e=(new Array).concat(t);for(let i=0;i<16;i++)t[i]=e[s[i]]},MixColumns(t){for(let s=0;s<16;s+=4){const e=t[s+0],i=t[s+1],n=t[s+2],o=t[s+3],h=e^i^n^o;t[s+0]^=h^r.xtime[e^i],t[s+1]^=h^r.xtime[i^n],t[s+2]^=h^r.xtime[n^o],t[s+3]^=h^r.xtime[o^e]}},MixColumns_Inv(t){for(let s=0;s<16;s+=4){const e=t[s+0],i=t[s+1],n=t[s+2],o=t[s+3],h=e^i^n^o,c=r.xtime[h],u=r.xtime[r.xtime[c^e^n]]^h,f=r.xtime[r.xtime[c^i^o]]^h;t[s+0]^=u^r.xtime[e^i],t[s+1]^=f^r.xtime[i^n],t[s+2]^=u^r.xtime[n^o],t[s+3]^=f^r.xtime[o^e]}}},n=[],o=256,h=Math.pow(2,52),c=2*h,u=Math.pow(o,6),f={seedrandom(t,s=!1){const e=[];t=m(a(s?[t,n]:arguments.length?t:[(new Date).getTime(),n],3),e);const i=new l(e);return m(i.S,n),f.random=function(){let t=i.g(6),s=u,e=0;for(;t<h;)t=(t+e)*o,s*=o,e=i.g(1);for(;t>=c;)t/=2,s/=2,e>>>=1;return(t+e)/s},t},random:function(){return Math.random()}};class l{i=0;j=0;S=[];c=[];constructor(t){let s,e,i=t.length,r=0,n=0;for(i||(t=[i++]);r<o;)this.S[r]=r++;for(r=0;r<o;r++)s=this.S[r],n=d(n+s+t[r%i]),e=this.S[n],this.S[r]=e,this.S[n]=s;this.g(o)}g(t){const s=this.S;let e=d(this.i+1),i=s[e],r=d(this.j+i),n=s[r];s[e]=n,s[r]=i;let h=s[d(i+n)];for(;--t;)e=d(e+1),i=s[e],r=d(r+i),n=s[r],s[e]=n,s[r]=i,h=h*o+s[d(i+n)];return this.i=e,this.j=r,h}}function a(t,s){const e=[],i=typeof t;if(s&&"object"===i
//# sourceMappingURL=cryptico.iife.js.map