text-encrypter
Version:
The library to encrypt/decrypt text using caesar cipher mechanism
3 lines (2 loc) • 1.06 kB
JavaScript
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e||self).textEncrypter={})}(this,function(e){var r=["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"];e.decrypt=function(e,o,n){void 0===o&&(o=1),void 0===n&&(n=!0);var t,i=[];return e.split("").map(function(e){n&&(e=r.includes(e.toLowerCase())?e:" ");var f=e.charCodeAt(0);if(" "===e)return i.push(e);if(f>=65&&f<=90){var d=f-65-o;t=String.fromCharCode(d>=0?d%26+65:(26+d)%26+65)}else if(f>=97&&f<=122){var u=f-97-o;t=String.fromCharCode(u>=0?u%26+97:(26+u)%26+97)}return i.push(t)}),i.join("")},e.encrypt=function(e,o,n){void 0===o&&(o=1),void 0===n&&(n=!0);var t,i=[];return e.split("").map(function(e){n&&(e=r.includes(e.toLowerCase())?e:" ");var f=e.charCodeAt(0);return" "===e?i.push(e):(f>=65&&f<=90?t=String.fromCharCode((f-65+o)%26+65):f>=97&&f<=122&&(t=String.fromCharCode((f-97+o)%26+97)),i.push(t))}),i.join("")}});
//# sourceMappingURL=index.umd.js.map