UNPKG

vignere-babbage-cipher-web

Version:
90 lines (88 loc) 6.56 kB
"use strict"; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _typeof2 = "function" == typeof Symbol && "symbol" == _typeof(Symbol.iterator) ? function (e) { return typeof e === "undefined" ? "undefined" : _typeof(e); } : function (e) { return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e === "undefined" ? "undefined" : _typeof(e); };!function (e) { if ("object" === ("undefined" == typeof exports ? "undefined" : _typeof2(exports)) && "undefined" != typeof module) module.exports = e();else if ("function" == typeof define && define.amd) define([], e);else { ("undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this).m = e(); } }(function () { return function i(u, f, c) { function l(t, e) { if (!f[t]) { if (!u[t]) { var n = "function" == typeof require && require;if (!e && n) return n(t, !0);if (a) return a(t, !0);var o = new Error("Cannot find module '" + t + "'");throw o.code = "MODULE_NOT_FOUND", o; }var r = f[t] = { exports: {} };u[t][0].call(r.exports, function (e) { return l(u[t][1][e] || e); }, r, r.exports, i, u, f, c); }return f[t].exports; }for (var a = "function" == typeof require && require, e = 0; e < c.length; e++) { l(c[e]); }return l; }({ 1: [function (t, n, e) { (function (e) { "undefined" == typeof document && (e.document = { querySelector: function querySelector() {}, addEventListener: function addEventListener() {} }, e.window = {});var u = t("elly"), f = t("vignere-babbage-cipher");window.onload = function () { function e() { var e = r.value.trim();if (e) { var t = u("[name='operation']:checked").value;if (o.textContent = f[t](i.value, e), "encrypt" === t) { var n = i.value.toUpperCase();f.decrypt(o.textContent, e) !== n && (o.textContent = "ERROR: Failed to encrypt the text successfully. Keep writing or remove punctuation such as new lines."); } } else o.textContent = "Please provide a key."; }var o = u("#result"), r = u("#key"), i = u("#text-input");i.addEventListener("input", e), r.addEventListener("input", e), u(".controls").addEventListener("change", e); }, n.exports = function () {}; }).call(this, "undefined" != typeof global ? global : "undefined" != typeof self ? self : "undefined" != typeof window ? window : {}); }, { elly: 2, "vignere-babbage-cipher": 5 }], 2: [function (e, t, n) { var o = e("iterate-object"), r = e("sliced");function i(n, e) { return "string" == typeof n ? "<" === n.charAt(0) ? (n = document.createElement(n.slice(1, -1)), o(e || {}, function (e, t) { switch (t) {case "text": return void (n.textContent = e);case "html": return void (n.innerHTML = e);}n.setAttribute(t, e); }), n) : (e = e || document).querySelector(n) : n; }i.$$ = function (e, t) { return "string" == typeof e ? (t = t || document, r(t.querySelectorAll(e))) : [e]; }, t.exports = i; }, { "iterate-object": 3, sliced: 4 }], 3: [function (e, t, n) { var r = "function" == typeof Symbol && "symbol" === _typeof2(Symbol.iterator) ? function (e) { return void 0 === e ? "undefined" : _typeof2(e); } : function (e) { return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : void 0 === e ? "undefined" : _typeof2(e); };t.exports = function (e, t) { var n = 0, o = [];if (Array.isArray(e)) for (; n < e.length && !1 !== t(e[n], n, e); ++n) {} else if ("object" === (void 0 === e ? "undefined" : r(e)) && null !== e) for (o = Object.keys(e); n < o.length && !1 !== t(e[o[n]], o[n], e); ++n) {} }; }, {}], 4: [function (e, t, n) { t.exports = function (e, t, n) { var o = [], r = e.length;if (0 === r) return o;var i = t < 0 ? Math.max(0, t + r) : t || 0;for (void 0 !== n && (r = n < 0 ? n + r : n); r-- > i;) { o[r - i] = e[r]; }return o; }; }, {}], 5: [function (e, t, n) { function o(e, t) { for (var n = 0; n < t.length; n++) { var o = t[n];o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, o.key, o); } }var i = { A: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", B: "BCDEFGHIJKLMNOPQRSTUVWXYZA", C: "CDEFGHIJKLMNOPQRSTUVWXYZAB", D: "DEFGHIJKLMNOPQRSTUVWXYZABC", E: "EFGHIJKLMNOPQRSTUVWXYZABCD", F: "FGHIJKLMNOPQRSTUVWXYZABCDE", G: "GHIJKLMNOPQRSTUVWXYZABCDEF", H: "HIJKLMNOPQRSTUVWXYZABCDEFG", I: "IJKLMNOPQRSTUVWXYZABCDEFGH", J: "JKLMNOPQRSTUVWXYZABCDEFGHI", K: "KLMNOPQRSTUVWXYZABCDEFGHIJ", L: "LMNOPQRSTUVWXYZABCDEFGHIJK", M: "MNOPQRSTUVWXYZABCDEFGHIJKL", N: "NOPQRSTUVWXYZABCDEFGHIJKLM", O: "OPQRSTUVWXYZABCDEFGHIJKLMN", P: "PQRSTUVWXYZABCDEFGHIJKLMNO", Q: "QRSTUVWXYZABCDEFGHIJKLMNOP", R: "RSTUVWXYZABCDEFGHIJKLMNOPQ", S: "STUVWXYZABCDEFGHIJKLMNOPQR", T: "TUVWXYZABCDEFGHIJKLMNOPQRS", U: "UVWXYZABCDEFGHIJKLMNOPQRST", V: "VWXYZABCDEFGHIJKLMNOPQRSTU", W: "WXYZABCDEFGHIJKLMNOPQRSTUV", X: "XYZABCDEFGHIJKLMNOPQRSTUVW", Y: "YZABCDEFGHIJKLMNOPQRSTUVWX", Z: "ZABCDEFGHIJKLMNOPQRSTUVWXY" }, r = (function (e, t, n) { return t && o(e.prototype, t), n && o(e, n), e; }(u, null, [{ key: "encrypt", value: function value(e, n) { e.length > n.length && (n += e.slice(0, e.length - n.length)), e = e.toUpperCase(), n = (n = n.toUpperCase()).replace(new RegExp("[^" + i.A + "]", "g"), "");var o = -1;return e.split("").map(function (e) { var t = i[e];return t ? t[i.A.indexOf(n[++o])] : e; }).join(""); } }, { key: "decrypt", value: function value(e, o) { e = e.toUpperCase(), o = o.toUpperCase();var r = 0;return e.split("").map(function (e) { var t = i[o[r]];if (!i[e]) return e;var n = i.A[t.indexOf(e)];return o += n, ++r, n; }).join(""); } }]), u);function u() { !function (e, t) { if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function"); }(this, u); }t.exports = r; }, {}] }, {}, [1])(1); });