Corrected padding and added error cases

This commit is contained in:
Flavio Diez 2020-01-27 14:43:00 +01:00
parent 2b39684904
commit ce638de9b1

View file

@ -48,10 +48,16 @@ class RailFenceCypherDecode extends Operation {
let cipher = input;
if (key < 2) {
return "Key has to be bigger than 2";
} else if (key > cipher.length) {
return "Key should be smaller than the cipher's length";
}
const rest = cipher.length % key;
if (rest !== 0) {
cipher = cipher + (" ".repeat(rest));
cipher = cipher + (" ".repeat(key-rest));
}
const blockLen = cipher.length / key;