diff --git a/src/core/operations/RailFenceCipherDecode.mjs b/src/core/operations/RailFenceCipherDecode.mjs index 5280bb1a..7317b438 100644 --- a/src/core/operations/RailFenceCipherDecode.mjs +++ b/src/core/operations/RailFenceCipherDecode.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; /** * Rail Fence Cipher Decode operation @@ -48,13 +49,13 @@ class RailFenceCipherDecode extends Operation { let cipher = input; if (key < 2) { - return "Key has to be bigger than 2"; + throw new OperationError("Key has to be bigger than 2"); } else if (key > cipher.length) { - return "Key should be smaller than the cipher's length"; + throw new OperationError("Key should be smaller than the cipher's length"); } if (offset < 0) { - return "Offset has to be a positive integer"; + throw new OperationError("Offset has to be a positive integer"); } const cycle = (key - 1) * 2; diff --git a/src/core/operations/RailFenceCipherEncode.mjs b/src/core/operations/RailFenceCipherEncode.mjs index 5d9d5eb1..af3a0016 100644 --- a/src/core/operations/RailFenceCipherEncode.mjs +++ b/src/core/operations/RailFenceCipherEncode.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; /** * Rail Fence Cipher Encode operation @@ -47,13 +48,13 @@ class RailFenceCipherEncode extends Operation { const plaintext = input; if (key < 2) { - return "Key has to be bigger than 2"; + throw new OperationError("Key has to be bigger than 2"); } else if (key > plaintext.length) { - return "Key should be smaller than the plain text's length"; + throw new OperationError("Key should be smaller than the plain text's length"); } if (offset < 0) { - return "Offset has to be a positive integer"; + throw new OperationError("Offset has to be a positive integer"); } const cycle = (key - 1) * 2;