diff --git a/src/blocks/affineDecrypt.js b/src/blocks/affineDecrypt.js index 1d6fb89..06da530 100644 --- a/src/blocks/affineDecrypt.js +++ b/src/blocks/affineDecrypt.js @@ -45,7 +45,7 @@ module.exports = { return text .split("") .map(require("./util/toNum.js")) - .map((num)=>(reverseLookupTable[num])) + .map((num)=>(Number.isInteger(num) ? reverseLookupTable[num] : num)) .map(require("./util/toChar.js")) .join(""); }, diff --git a/src/blocks/affineEncrypt.js b/src/blocks/affineEncrypt.js index e9aaa79..e0dd38d 100644 --- a/src/blocks/affineEncrypt.js +++ b/src/blocks/affineEncrypt.js @@ -45,7 +45,7 @@ module.exports = { return text .split("") .map(require("./util/toNum.js")) - .map((num)=>(lookupTable[num])) + .map((num)=>(Number.isInteger(num) ? lookupTable[num] : num)) .map(require("./util/toChar.js")) .join(""); }, diff --git a/src/blocks/substitution.js b/src/blocks/substitution.js index 600e73c..500a2f6 100644 --- a/src/blocks/substitution.js +++ b/src/blocks/substitution.js @@ -18,7 +18,7 @@ module.exports = { execute: function({text, mapping}, elem){ mapping = mapping.toLowerCase(); var letterMapping = {}; - for(var i = 0; i < (mapping.length - 1); i++){ + for(var i = 0; i < (mapping.length - 1); i = i + 2){ letterMapping[mapping[i]] = mapping[i+1]; } @@ -26,15 +26,10 @@ module.exports = { .split("") .map((char)=>{ if(char.toLowerCase() in letterMapping){ - if(char.toLowerCase() == char){ - return letterMapping[char]; - } - else{ - return letterMapping[char.toLowerCase()].toUpperCase(); - } + return letterMapping[char.toLowerCase()] } else{ - return char; + return char.toLowerCase(); } }) .join("");