UNPKG

krypton-grapher

Version:

Krypton Grapher is a lightweight JavaScript library for encrypting and decrypting text with ease. It offers simple APIs for implementing text security in your applications, whether for personal projects or professional use. Designed with flexibility an

1 lines 751 B
export class Cryptographer{#e="ABCDEFGHIJKLMNOPQRSTUVWXYZ";#t="АБВГҐДЕЄЖЗИІЇЙКЛМНОПРСТУФХЦЧШЩЬЮЯ";#r(e){if(this.#e.includes(e.toUpperCase())){return this.#e}else if(this.#t.includes(e.toUpperCase())){return this.#t}return null}#s(e,t,r){if(r)t=-t;let s="";for(const r of e){const e=this.#r(r);if(e!==null){const n=r===r.toLowerCase();let l=(e.indexOf(r.toUpperCase())+t)%e.length;if(l<0)l+=e.length;const h=e.charAt(l);s+=n?h.toLowerCase():h}else{s+=r}}return s}encrypt(e,t){return this.#s(e,t,false)}decrypt(e,t,r){if(r!==undefined){return this.#s(e,r,true)}else{const r=t==="en"?this.#e:this.#t;if(!r)throw new Error("Unsupported language!");let s=[];for(let t=0;t<r.length;t++){s.push(this.#s(e,t,true))}return s}}}