(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const u of document.querySelectorAll('link[rel="modulepreload"]'))g(u);new MutationObserver(u=>{for(const f of u)if(f.type==="childList")for(const s of f.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&g(s)}).observe(document,{childList:!0,subtree:!0});function c(u){const f={};return u.integrity&&(f.integrity=u.integrity),u.referrerPolicy&&(f.referrerPolicy=u.referrerPolicy),u.crossOrigin==="use-credentials"?f.credentials="include":u.crossOrigin==="anonymous"?f.credentials="omit":f.credentials="same-origin",f}function g(u){if(u.ep)return;u.ep=!0;const f=c(u);fetch(u.href,f)}})();const I={3:{unifier:"­",0:"᠎",1:"​",2:"‍"},6:{unifier:"‌",0:"‍",1:"‏",2:"­",3:"⁠",4:"​",5:"‎"},7:{unifier:"‌",0:"‍",1:"‏",2:"­",3:"⁠",4:"​",5:"‎",6:"\uFEFF"},encodeString:(e,t=7)=>Array.from(e,c=>(+t==7?ge(c):c.codePointAt(0)).toString(t).split("").map(g=>I[t][g]).join("")).join(I[t].unifier),encodeNumberArray:(e,t=7)=>e.map(c=>c.toString(t).split("").map(g=>I[t][g]).join("")).join(I[t].unifier),decodeToString:(e,t=7)=>I.decodeToNumberArray(e,t).map(c=>String.fromCodePoint(+t==7?he(c):c)).join(""),decodeToNumberArray:(e,t=7)=>e.split(I[t].unifier).map(c=>Array.from(c).map(g=>Object.keys(I[t]).find(u=>I[t][u]===g)).join("")).filter(Boolean).map(c=>parseInt(c,t))},de="te aoinshrdlucmfwypvbgkjqxz.,!?'-:;()0123456789ETAOINSHRDLUCMFWYPVBGKJQXZ",X=[...new Set([...de,...Array.from({length:95},(e,t)=>String.fromCharCode(t+32))])],pe=new Map(X.map((e,t)=>[e,t])),ge=e=>pe.get(e)??(e.codePointAt(0)<32?e.codePointAt(0)+95:e.codePointAt(0)),he=e=>e<95?X[e].codePointAt(0):e<127?e-95:e,J=65536;function Q(e,t,c){const g=[];for(let u=0;u=55296&&e.charCodeAt(f-1)<=56319&&f--,g.push(I[c](e.slice(u,f),t)),u=f}return g.join(I[t].unifier)}function ee(e,t,c){const g=[],u=I[t].unifier;for(let f=0;f=f?n+1:e.indexOf(u,s)+1||e.length}g.push(I[c](e.slice(f,s),t)),f=s}return c==="decodeToString"?g.join(""):g.flat()}const be=(e,t)=>Q(e,t,"encodeString"),M=(e,t)=>Q(e,t,"encodeNumberArray"),ye=(e,t)=>ee(e,t,"decodeToString"),v=(e,t)=>ee(e,t,"decodeToNumberArray");function me(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var F,G;function Ae(){if(G)return F;G=1;function e(t={}){const c=t.bits||16,g=t.rounds||22,u=t.rightRotations||7,f=t.leftRotations||2,s=2**c,n=s-1,a=(l,o)=>l>>o|l<l<>c-o,m=(l,o,r)=>(l=a(l,u),l=l+o&n,l^=r,o=y(o,f),o^=l,[l,o]),w=(l,o,r)=>(o^=l,o=a(o,f),l^=r,l=l-o&n,l=y(l,u),[l,o]);function k(l,o){let r=l[0],d=l[1],i=o[0],h=o.slice(1);[d,r]=m(d,r,i);for(let b=0;b{const d=l([o/s|0,o&n],r);return d[0]*s+d[1]}}return{encrypt:p(k),decrypt:p(E),encryptRaw:k,decryptRaw:E}}return F=e,F}var we=Ae();const te=me(we);var P,K;function ne(){if(K)return P;K=1;const e="Input must be an string, Buffer or Uint8Array";function t(s){let n;if(s instanceof Uint8Array)n=s;else if(typeof s=="string")n=new TextEncoder().encode(s);else throw new Error(e);return n}function c(s){return Array.prototype.map.call(s,function(n){return(n<16?"0":"")+n.toString(16)}).join("")}function g(s){return(4294967296+s).toString(16).substring(1)}function u(s,n,a){let y=` `+s+" = ";for(let m=0;m=4294967296&&b++,r[d]=h,r[d+1]=b}function c(r,d,i,h){let b=r[d]+i;i<0&&(b+=4294967296);let A=r[d+1]+h;b>=4294967296&&A++,r[d]=b,r[d+1]=A}function g(r,d){return r[d]^r[d+1]<<8^r[d+2]<<16^r[d+3]<<24}function u(r,d,i,h,b,A){const le=y[b],ae=y[b+1],ue=y[A],fe=y[A+1];t(a,r,d),c(a,r,le,ae);let S=a[h]^a[r],C=a[h+1]^a[r+1];a[h]=C,a[h+1]=S,t(a,i,h),S=a[d]^a[i],C=a[d+1]^a[i+1],a[d]=S>>>24^C<<8,a[d+1]=C>>>24^S<<8,t(a,r,d),c(a,r,ue,fe),S=a[h]^a[r],C=a[h+1]^a[r+1],a[h]=S>>>16^C<<16,a[h+1]=C>>>16^S<<16,t(a,i,h),S=a[d]^a[i],C=a[d+1]^a[i+1],a[d]=C>>>31^S<<1,a[d+1]=S>>>31^C<<1}const f=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),s=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3],n=new Uint8Array(s.map(function(r){return r*2})),a=new Uint32Array(32),y=new Uint32Array(32);function m(r,d){let i=0;for(i=0;i<16;i++)a[i]=r.h[i],a[i+16]=f[i];for(a[24]=a[24]^r.t,a[25]=a[25]^r.t/4294967296,d&&(a[28]=~a[28],a[29]=~a[29]),i=0;i<32;i++)y[i]=g(r.b,4*i);for(i=0;i<12;i++)u(0,8,16,24,n[i*16+0],n[i*16+1]),u(2,10,18,26,n[i*16+2],n[i*16+3]),u(4,12,20,28,n[i*16+4],n[i*16+5]),u(6,14,22,30,n[i*16+6],n[i*16+7]),u(0,10,20,30,n[i*16+8],n[i*16+9]),u(2,12,22,24,n[i*16+10],n[i*16+11]),u(4,14,16,26,n[i*16+12],n[i*16+13]),u(6,8,18,28,n[i*16+14],n[i*16+15]);for(i=0;i<16;i++)r.h[i]=r.h[i]^a[i]^a[i+16]}const w=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);function k(r,d,i,h){if(r===0||r>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(d&&d.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");if(i&&i.length!==16)throw new Error("Illegal salt, expected Uint8Array with length is 16");if(h&&h.length!==16)throw new Error("Illegal personal, expected Uint8Array with length is 16");const b={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:r};w.fill(0),w[0]=r,d&&(w[1]=d.length),w[2]=1,w[3]=1,i&&w.set(i,32),h&&w.set(h,48);for(let A=0;A<16;A++)b.h[A]=f[A]^g(w,A*4);return d&&(E(b,d),b.c=128),b}function E(r,d){for(let i=0;i>2]>>8*(i&3);return d}function l(r,d,i,h,b){i=i||64,r=e.normalizeInput(r),h&&(h=e.normalizeInput(h)),b&&(b=e.normalizeInput(b));const A=k(i,d,h,b);return E(A,r),p(A)}function o(r,d,i,h,b){const A=l(r,d,i,h,b);return e.toHex(A)}return O={blake2b:l,blake2bHex:o,blake2bInit:k,blake2bUpdate:E,blake2bFinal:p},O}var R,z;function ke(){if(z)return R;z=1;const e=ne();function t(p,l){return p[l]^p[l+1]<<8^p[l+2]<<16^p[l+3]<<24}function c(p,l,o,r,d,i){s[p]=s[p]+s[l]+d,s[r]=g(s[r]^s[p],16),s[o]=s[o]+s[r],s[l]=g(s[l]^s[o],12),s[p]=s[p]+s[l]+i,s[r]=g(s[r]^s[p],8),s[o]=s[o]+s[r],s[l]=g(s[l]^s[o],7)}function g(p,l){return p>>>l^p<<32-l}const u=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),f=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0]),s=new Uint32Array(16),n=new Uint32Array(16);function a(p,l){let o=0;for(o=0;o<8;o++)s[o]=p.h[o],s[o+8]=u[o];for(s[12]^=p.t,s[13]^=p.t/4294967296,l&&(s[14]=~s[14]),o=0;o<16;o++)n[o]=t(p.b,4*o);for(o=0;o<10;o++)c(0,4,8,12,n[f[o*16+0]],n[f[o*16+1]]),c(1,5,9,13,n[f[o*16+2]],n[f[o*16+3]]),c(2,6,10,14,n[f[o*16+4]],n[f[o*16+5]]),c(3,7,11,15,n[f[o*16+6]],n[f[o*16+7]]),c(0,5,10,15,n[f[o*16+8]],n[f[o*16+9]]),c(1,6,11,12,n[f[o*16+10]],n[f[o*16+11]]),c(2,7,8,13,n[f[o*16+12]],n[f[o*16+13]]),c(3,4,9,14,n[f[o*16+14]],n[f[o*16+15]]);for(o=0;o<8;o++)p.h[o]^=s[o]^s[o+8]}function y(p,l){if(!(p>0&&p<=32))throw new Error("Incorrect output length, should be in [1, 32]");const o=l?l.length:0;if(l&&!(o>0&&o<=32))throw new Error("Incorrect key length, should be in [1, 32]");const r={h:new Uint32Array(u),b:new Uint8Array(64),c:0,t:0,outlen:p};return r.h[0]^=16842752^o<<8^p,o>0&&(m(r,l),r.c=64),r}function m(p,l){for(let o=0;o>2]>>8*(o&3)&255;return l}function k(p,l,o){o=o||32,p=e.normalizeInput(p);const r=y(o,l);return m(r,p),w(r)}function E(p,l,o){const r=k(p,l,o);return e.toHex(r)}return R={blake2s:k,blake2sHex:E,blake2sInit:y,blake2sUpdate:m,blake2sFinal:w},R}var _,$;function Ee(){if($)return _;$=1;const e=Ie(),t=ke();return _={blake2b:e.blake2b,blake2bHex:e.blake2bHex,blake2bInit:e.blake2bInit,blake2bUpdate:e.blake2bUpdate,blake2bFinal:e.blake2bFinal,blake2s:t.blake2s,blake2sHex:t.blake2sHex,blake2sInit:t.blake2sInit,blake2sUpdate:t.blake2sUpdate,blake2sFinal:t.blake2sFinal},_}var re=Ee();const oe=te({bits:24,rounds:23,rightRotations:8,leftRotations:3});function W(e){const t=re.blake2bHex(e,null,12);return[parseInt(t.slice(0,6),16),parseInt(t.slice(6,12),16),parseInt(t.slice(12,18),16),parseInt(t.slice(18,24),16)]}function Se(e,t){const c=globalThis.crypto.getRandomValues(new Uint32Array(1))[0]&16777215,g=Array.from(e,(u,f)=>{const s=c*16777216+(f&16777215),n=oe.encrypt(s,t);return(u.codePointAt(0)^n)>>>0});return[c,...g]}function Ce(e,t){if(!e||e.length===0)return"";const c=e[0];return e.slice(1).map((u,f)=>{const s=c*16777216+(f&16777215),n=oe.encrypt(s,t),a=(u^n)>>>0;try{return String.fromCodePoint(a)}catch{return""}}).join("")}const ie=te();function Y(e){const t=re.blake2bHex(e,null,8);return[parseInt(t.slice(0,4),16),parseInt(t.slice(4,8),16),parseInt(t.slice(8,12),16),parseInt(t.slice(12,16),16)]}function Be(e,t){return Array.from(e,c=>ie.encrypt(c.codePointAt(0),t))}function Te(e,t){return e.map(c=>{try{return String.fromCodePoint(ie.decrypt(c,t))}catch{return""}}).join("")}const j="‍​­",B={3:"‍​­᠎‍",6:"‍​­‌‍",7:"‍​­‌‌"},ce={1:"SPECK48_96CTR",2:"SPECK32_64ECB (insecure)"},Ue=Object.fromEntries(Object.entries(ce).map(([e,t])=>[t,+e]));function De(e,t){let c=B[e];const g=Ue[t];if(g){const u=Array.from(g.toString(e).padStart(3,"0"),f=>I[e][f]).join("");c+=I[e].unifier+I[e][0]+u}return c}function Fe(e){let t=e.indexOf(j),c;for(;t!==-1&&(c=Object.keys(B).find(f=>e.startsWith(B[f],t)),!c);)t=e.indexOf(j,t+j.length);if(!c)return null;const g=e.slice(t+B[c].length),u=I[c].unifier+I[c][0];if(g.startsWith(u)){const s=Array.from(g.slice(u.length,u.length+3)).map(m=>Object.keys(I[c]).find(w=>I[c][w]===m)).join(""),n=ce[parseInt(s,c)];if(!n)return{base:c,cipher:"PLAIN",payload:g,sigIdx:t,sigLen:B[c].length};const a=g.slice(u.length+3),y=B[c].length+u.length+3;return{base:c,cipher:n,payload:a,sigIdx:t,sigLen:y}}return{base:c,cipher:"PLAIN",payload:g,sigIdx:t,sigLen:B[c].length}}const T=document.getElementById("textarea"),N=document.getElementById("encoder"),L=document.getElementById("cipher"),H=document.getElementById("sign"),D=document.getElementById("sigDetect"),U=document.getElementById("notice"),Pe=["encodeButton","decodeButton"].map(e=>document.getElementById(e)),V=[...Pe,N,L,H];document.getElementById("encodeButton").addEventListener("click",se);document.getElementById("decodeButton").addEventListener("click",se);H.addEventListener("click",e=>e.target.classList.toggle("on"));let Z,x=!1;async function se(e){if(x)return;if(clearTimeout(Z),D.className="",T.value===""){T.value="The text box is empty.";return}const t=e.target.id==="encodeButton"?"NO":"YES";let c=Re(),g=N.value.split("-")[1],u=T.value;if(t==="YES"){const n=Fe(u);if(n){if(n.base!==g||n.cipher&&n.cipher!==c){const a=n.cipher&&n.cipher!=="PLAIN"?` (${n.cipher})`:"";D.textContent=`ZWUS-${n.base}${a} signature detected`,D.className="show",Z=setTimeout(()=>D.className="",2e3)}g=n.base,N.value="ZWUS-"+g,n.cipher&&(c=n.cipher,L.value=c),u=u.slice(0,n.sigIdx)+n.payload}}const f=c!=="PLAIN",s=f&&prompt("enter password.");if(!(f&&!s)){x=!0,V.forEach(n=>n.disabled=!0),U.textContent="Processing…";try{let n=await _e[t][c](u,g,s);if(t==="NO"&&H.classList.contains("on")&&(n=De(g,c)+n),T.value=n,t==="NO"){U.textContent="Copying…";const a=await Oe(n);a&&n.length<=65536&&(T.value=`Copied to your clipboard. A copy has been placed between these brackets [`+n+"]"),U.textContent=a?`Copied ${n.length.toLocaleString()} characters.`:"Copy failed. The encoded text is in the box; select and copy it manually."}else U.textContent=`Decoded ${n.length.toLocaleString()} characters.`}catch(n){console.error(n),U.textContent=`Could not ${t==="NO"?"encode":"decode"}: ${n.message}`}finally{x=!1,V.forEach(n=>n.disabled=!1)}}}async function Oe(e){var t;if((t=navigator.clipboard)!=null&&t.writeText){let c;try{return await Promise.race([navigator.clipboard.writeText(e),new Promise((g,u)=>c=setTimeout(()=>u(new Error("Copy timed out")),5e3))]),!0}catch(g){console.warn("Clipboard copy failed",g)}finally{clearTimeout(c)}}if(e.length>65536)return!1;T.select();try{return document.execCommand("copy")}catch(c){return console.warn("Clipboard copy failed",c),!1}}function Re(){return L.value}const _e={NO:{PLAIN:(e,t)=>be(e,t),SPECK48_96CTR:(e,t,c)=>M(Se(e,W(c)),t),"SPECK32_64ECB (insecure)":(e,t,c)=>M(Be(e,Y(c)),t)},YES:{PLAIN:(e,t)=>ye(e,t),SPECK48_96CTR:async(e,t,c)=>Ce(await v(e,t),W(c)),"SPECK32_64ECB (insecure)":async(e,t,c)=>Te(await v(e,t),Y(c))}};