Skip to content

Commit e36f87c

Browse files
authored
added exception in MonoAlphabetic.java
1 parent abfe77e commit e36f87c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/main/java/com/thealgorithms/ciphers/MonoAlphabetic.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ private MonoAlphabetic() {
88

99
// Encryption method
1010
public static String encrypt(String data, String key) {
11+
if (!data.matches("[A-Z]+")) {
12+
throw new IllegalArgumentException("Input data contains invalid characters. Only uppercase A-Z are allowed.");
13+
}
1114
StringBuilder sb = new StringBuilder();
1215
data = data.toUpperCase();
1316

0 commit comments

Comments
 (0)