UNPKG

@ddunigma/node

Version:
1 lines 1.69 kB
import {g as g$1}from'./chunk-TCRCZHZC.js';import {n}from'./chunk-IZK7KCU7.js';import {a}from'./chunk-EI7MMDWY.js';var i=44032,h=55203,c=h-i+1;function u(t){if(t.length===0)throw new n("[Ddu64 obfuscation] Alphabet must not be empty.");if(t.length>c)throw new n(`[Ddu64 obfuscation] Alphabet size (${t.length}) exceeds available Hangul syllables (${c}).`);let r=Math.floor(c/t.length),n$1=new Map;for(let e=0;e<t.length;e++)n$1.set(t[e],e);return {alphabet:t,syllablesPerChar:r,charToIndex:n$1}}a(u,"buildSyllableMap");function g(t,r,n){let e=i+t*n.syllablesPerChar,o=r%n.syllablesPerChar;return e+o}a(g,"charToSyllable");function d(t,r){if(t<i||t>h)return -1;let n=t-i,e=Math.floor(n/r.syllablesPerChar);return e>=r.alphabet.length?-1:e}a(d,"syllableToCharIndex");var f=class{static{a(this,"HangulObfuscationLayer");}config;constructor(r){this.config=u(r);}obfuscate(r){if(r.length===0)return "";let n$1=new Array(r.length);for(let e=0;e<r.length;e++){let o=r[e],s=this.config.charToIndex.get(o);if(s===void 0)throw new n(`[Ddu64 obfuscation] Character "${o}" (U+${o.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase()}) not found in obfuscation alphabet.`);let p=g(s,e,this.config);n$1[e]=String.fromCharCode(p);}return n$1.join("")}deobfuscate(r){if(r.length===0)return "";let n$1=new Array(r.length);for(let e=0;e<r.length;e++){let o=r.charCodeAt(e),s=d(o,this.config);if(s===-1)throw new n(`[Ddu64 obfuscation] Invalid syllable at position ${e}: U+${o.toString(16).padStart(4,"0").toUpperCase()} is not in the mapped range.`);n$1[e]=this.config.alphabet[s];}return n$1.join("")}};function A(t,r){return new f(g$1(t,r))}a(A,"createEncoderObfuscationLayer");export{f as a,A as b};