Corrected padding and added error cases
This commit is contained in:
parent
2b39684904
commit
ce638de9b1
@ -48,10 +48,16 @@ class RailFenceCypherDecode extends Operation {
|
|||||||
|
|
||||||
let cipher = input;
|
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;
|
const rest = cipher.length % key;
|
||||||
|
|
||||||
if (rest !== 0) {
|
if (rest !== 0) {
|
||||||
cipher = cipher + (" ".repeat(rest));
|
cipher = cipher + (" ".repeat(key-rest));
|
||||||
}
|
}
|
||||||
|
|
||||||
const blockLen = cipher.length / key;
|
const blockLen = cipher.length / key;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user