Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Cipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -15,19 +15,24 @@ 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;
}

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;
}

Expand All @@ -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);
}
}
}
Expand All @@ -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;
}
}
}