-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcipher.min.js
1 lines (1 loc) · 1.01 KB
/
cipher.min.js
1
const cipher=["AAAAA","AAAAB","AAABA","AAABB","AABAA","AABAB","AABBA","AABBB","ABAAA","ABAAB","ABABA","ABABB","ABBAA","ABBAB","ABBBA","ABBBB","BAAAA","BAAAB","BAABA","BAABB","BABAA","BABAB","BABBA","BABBB","BBAAA","BBAAB"],orig=["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"];function encode(a=""){const b=[],c=a.split("");for(let d=0;d<c.length;d++){const a=c[d].toUpperCase();if(orig.includes(a)){const c=orig.indexOf(a);b.push(cipher[c])}else b.push(a)}return b.join("")}function decode(a="",b=!0){const c=[],d=a.split("");let e=[];for(let f=0;f<d.length;f++){const a=d[f].toUpperCase();if(!/[AB]/.test(a))c.push(a);else if(4===e.length){e.push(a);const b=cipher.indexOf(e.join(""));c.push(orig[b]),e=[]}else e.push(a)}return b?titleCase(c.join("")):c.join("")}function titleCase(a=""){return a.toLowerCase().split(" ").map(a=>a.replace(a.charAt(0),a.charAt(0).toUpperCase())).join(" ")}const version=require("./package.json").version;module.exports={encode,decode,version};