diff --git a/Cipher.java b/Cipher.java index 7527c5b..d78deb5 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; @@ -26,8 +27,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 i = 0; i < inputString.length(); i++) + { + // append the encrypted version of the char to the output string + outputString += replaceChar(inputString.charAt(i), false); + } + return outputString; } @@ -42,7 +48,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); } } } diff --git a/README.md b/README.md index dc8ac3b..6812485 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# CS102-Git-Tutorial - - * This repository contains a tiny cipher program. Two people were involved in the development process. The first developer completed the task but thought it would be fun to replace some of the code with encoded text. Now the program is not working. The second developer, unfortunately, thought that it would be better to eliminate the syntax errors first by deleting the problematic code. This got rid of the errors, but the program is not doing what we want. - - * As our new developer, you should first **fork** this project to work on your own copy. - - * Then we advise you to roll back one version, as the code was easier to fix before the second developer was involved. - - * **Commit** and **push** the fixed version of the program to your repository. - - * Finally open a **pull request** to the original repository. +# CS102-Git-Tutorial + + * This repository contains a tiny cipher program. Two people were involved in the development process. The first developer completed the task but thought it would be fun to replace some of the code with encoded text. Now the program is not working. The second developer, unfortunately, thought that it would be better to eliminate the syntax errors first by deleting the problematic code. This got rid of the errors, but the program is not doing what we want. + + * As our new developer, you should first **fork** this project to work on your own copy. + + * Then we advise you to roll back one version, as the code was easier to fix before the second developer was involved. + + * **Commit** and **push** the fixed version of the program to your repository. + + * Finally open a **pull request** to the original repository.