function lisaCipher(keyword, msg) { var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; var plainText = ""; var remainderAlphabet = alphabet.split(""); var plainAlphabet = alphabet.split(""); var cypherAlphabet = []; var cypherChars = ((keyword.replace(/\s/g, '')).toUpperCase()).split(""); var msgText = msg.toUpperCase().split(""); for (i=0; i < cypherChars.length;i++) { if (cypherAlphabet.includes(cypherChars[i]) === false) { cypherAlphabet.push(cypherChars[i]); } } remainderAlphabet = remainderAlphabet.filter(char => cypherAlphabet.includes(char) === false); remainderAlphabet.forEach(char => cypherAlphabet.push(char)); for (char of msgText) { if (plainAlphabet.includes(char) === false) { plainAlphabet.push(char); cypherAlphabet.push(char); } plainText = plainText + plainAlphabet[cypherAlphabet.findIndex(cipherChar => cipherChar === char)]; } return plainText; }
- function lisaCipher(keyword, msg) {
- var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- var plainText = "";
- var remainderAlphabet = alphabet.split("");
- var plainAlphabet = alphabet.split("");
- var cypherAlphabet = [];
- var cypherChars = ((keyword.replace(/\s/g, '')).toUpperCase()).split("");
- var msgText = msg.toUpperCase().split("");
- for (i=0; i < cypherChars.length;i++) {
- if (cypherAlphabet.includes(cypherChars[i]) === false) {
- cypherAlphabet.push(cypherChars[i]);
- }
- }
- remainderAlphabet = remainderAlphabet.filter(char => cypherAlphabet.includes(char) === false);
- remainderAlphabet.forEach(char => cypherAlphabet.push(char));
- for (char of msgText) {
- if (plainAlphabet.includes(char) === false) {
- plainAlphabet.push(char);
- cypherAlphabet.push(char);
- }
- plainText = plainText + plainAlphabet[cypherAlphabet.findIndex(cipherChar => cipherChar === char)];
- }
- return plainText;
- }