Fixed bug, made vigenere much faster
This commit is contained in:
parent
6be2b7bcaa
commit
37cdd8bbc6
@ -6,7 +6,7 @@ function getGroups(text, size){
|
||||
.toLowerCase()
|
||||
.split(/[^a-z]/) //split on any non a-z character to get words
|
||||
.map((word)=>{ //turn each word into all size-length groups
|
||||
groups = []
|
||||
var groups = []
|
||||
for(var i = 0; i <= (word.length - size); i++){
|
||||
groups.push(word.substr(i, size));
|
||||
}
|
||||
|
@ -18,13 +18,14 @@ 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)){
|
||||
var realCharsPosition = ints.slice(0, pos).filter((num)=>(Number.isInteger(num))).length;
|
||||
return (int + 26 - keyNums[realCharsPosition%key.length])%26;
|
||||
i++
|
||||
return (int + 26 - keyNums[i%key.length])%26;
|
||||
}
|
||||
else{
|
||||
return int;
|
||||
|
@ -17,20 +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)=>{
|
||||
if(Number.isInteger(int)){
|
||||
var realCharsPosition = ints.slice(0, pos).filter((num)=>(Number.isInteger(num))).length;
|
||||
return (int + keyNums[realCharsPosition % key.length]) % 26;
|
||||
i++;
|
||||
return (int + keyNums[i % key.length]) % 26;
|
||||
}
|
||||
else{
|
||||
return int;
|
||||
}
|
||||
})
|
||||
.filter((a)=>(!Number.isNaN(a)))
|
||||
.map(require("./util/toChar.js"))
|
||||
.join("");
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user