Much nicer vigenere fix

This commit is contained in:
Tim Stallard 2017-04-04 22:08:25 +01:00
parent 37cdd8bbc6
commit a172488746
2 changed files with 8 additions and 9 deletions

View File

@ -18,19 +18,18 @@ module.exports = {
execute: function({cipherText, key}, elem){
var keyNums = key.split("").map(require("./util/toNum.js"));
var i = 0;
return cipherText
.split("")
.map(require("./util/toNum.js"))
.map((int, pos, ints)=>{
if(Number.isInteger(int)){
i++
return (int + 26 - keyNums[i%key.length])%26;
this.i++;
return (int + 26 - keyNums[this.i%key.length])%26;
}
else{
return int;
}
})
}, {i: -1})
.map(require("./util/toChar.js"))
.join("");
},

View File

@ -17,19 +17,19 @@ module.exports = {
output: true,
execute: function({plaintext, key}, elem){
var keyNums = key.split("").map(require("./util/toNum.js"));
var i = 0;
return plaintext
.split("")
.map(require("./util/toNum.js"))
.map((int, pos, ints)=>{
.map(function(int, pos, ints){
if(Number.isInteger(int)){
i++;
return (int + keyNums[i % key.length]) % 26;
this.i++;
return val = (int + keyNums[this.i % key.length]) % 26;
}
else{
return int;
}
})
}, {i: -1})
.map(require("./util/toChar.js"))
.join("");
},