From 2922e56c9a6a99fb36febbca9a736b42032a4360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ka=C4=9Fan?= Date: Wed, 24 Sep 2025 16:23:50 +0300 Subject: [PATCH 1/2] Update Cipher.java I have fixed the syntax errors. --- Cipher.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Cipher.java b/Cipher.java index 7527c5b..be875ac 100644 --- a/Cipher.java +++ b/Cipher.java @@ -5,7 +5,7 @@ public class Cipher // encryption involves mapping from original to cipher, for each letter we locate the character in the // original string and replace it with the cipher alphabet letter at the same position public static final String ORIGINAL_ALPHABET = "abcdefghijklmnopqrstuvwxyz"; - public static final String CIPHER_ALPHABET = "dfxyhrklvwuasgimnojpqetbcz"; + public static final String CIPHER_ALPHABET = "dfxyhrklvwuasgimnojpqetbcz"; public String encrypt(String inputString) { @@ -15,7 +15,8 @@ public String encrypt(String inputString) { // for all chars in the input string for (int i = 0; i < inputString.length(); i++) { - + // append the encrypted version of the char to the output string + outputString += replaceChar(inputString.charAt(i), true); } return outputString; @@ -23,11 +24,15 @@ public String encrypt(String inputString) { public String decrypt(String inputString) { - // output string will be collected in this variable, one char at a time String outputString = ""; - replaceChar('a',true); - + + for (int i = 0; i < inputString.length(); i++) + { + + outputString += replaceChar(inputString.charAt(i), false); + } + return outputString; } @@ -42,7 +47,7 @@ private char replaceChar(char inputChar, boolean isEncrypt) { for (int i = 0; i < ORIGINAL_ALPHABET.length(); i++) { if(ORIGINAL_ALPHABET.charAt(i) == inputChar) { - + return CIPHER_ALPHABET.charAt(i); } } } @@ -58,4 +63,4 @@ private char replaceChar(char inputChar, boolean isEncrypt) { // if we did not find it in the alphabet, then return the original char return inputChar; } -} \ No newline at end of file +} From 2795aab33687a6081a3d9b6fbd05c8e3f40e231d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ka=C4=9Fan?= Date: Wed, 24 Sep 2025 16:24:45 +0300 Subject: [PATCH 2/2] Update CipherTest.java It was working well so I didn't change anything.