From b706134a929eac33a3f629bc2dd0b78b105c59d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damla=20Ba=C5=9Fak=20U=C3=A7ar?= Date: Wed, 25 Sep 2024 15:46:38 +0300 Subject: [PATCH 1/2] Fixed --- Cipher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cipher.java b/Cipher.java index 7527c5b..5b05da6 100644 --- a/Cipher.java +++ b/Cipher.java @@ -15,7 +15,7 @@ public String encrypt(String inputString) { // for all chars in the input string for (int i = 0; i < inputString.length(); i++) { - + outputString+= } return outputString; From 83adff87edbb5914f686cbd08b9aa6ba653ea38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damla=20Ba=C5=9Fak=20U=C3=A7ar?= Date: Wed, 25 Sep 2024 15:49:10 +0300 Subject: [PATCH 2/2] Fixed --- Cipher.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Cipher.java b/Cipher.java index 5b05da6..39a67cf 100644 --- a/Cipher.java +++ b/Cipher.java @@ -1,3 +1,4 @@ +package denemeAA; // This class is used for encrypting or decrypting strings using character mapping public class Cipher { @@ -15,7 +16,8 @@ public String encrypt(String inputString) { // for all chars in the input string for (int i = 0; i < inputString.length(); i++) { - outputString+= + // append the encrypted version of the char to the output string + outputString += replaceChar(inputString.charAt(i),true); } return outputString; @@ -26,8 +28,13 @@ public String decrypt(String inputString) { // output string will be collected in this variable, one char at a time String outputString = ""; - replaceChar('a',true); - + // for all chars in the input string + for (int v = 0; v < inputString.length(); v++) + { + // append the encrypted version of the char to the output string + outputString += replaceChar(inputString.charAt(v), false); + } + return outputString; } @@ -42,7 +49,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 +65,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 +} \ No newline at end of file