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