this is the outpu that i am getting:
Transpose The encrypted message is wkh txlfn eurzq ira The decrypted message is the quick brown fox The encrypted Transpose message is wkh txlfn eurzq ira The decripted Transpose message is eht kciuq nworb xof <--------------------- I need this to be on encrypted Transpose and here it should be the decrypted message like on the first one Reverser The encrypted Reverse message is xof nworb kciuq eht The decrypted Reverse message is qeb nrfzh yoltk clu <-------------------- I also need the decrypted message here like on the first one
I believe the problem is in my methods (loop), but i have tried every possible configuration of the loop and this is as close as I can get it to the right output. Here is the code of all the classes.
package assignment2; public class Caeser extends Cipher { public Caeser(String s) { super(s); } public String encode(String word) { StringBuilder result = new StringBuilder(); for (int i = 0; i < word.length(); i ++) { char ch = word.charAt(i); ch = determineCharacter(ch, Constants.ENCODE_SHIFT); result.append(ch); } return result.toString(); } public String decode(String word) { StringBuilder result = new StringBuilder(); for (int i = 0; i < word.length(); i ++) { char ch = word.charAt(i); ch = determineCharacter(ch, Constants.DECODE_SHIFT); result.append(ch); } return result.toString(); } public char determineCharacter(char ch, int shift) { if(Character.isLowerCase(ch) || Character.isUpperCase(ch)) ch = (char)('a' + (ch - 'a' + shift) % Constants.WRAP_AROUND); return ch; } }package assignment2; public class Transpose extends Cipher { Transpose(String s) { super(s); } public String encode(String word) { StringBuilder result = new StringBuilder(); for (int i= 0; i < word.length(); i++) { char ch = word.charAt(i); ch = determineCharacter(ch, Constants.ENCODE_SHIFT); result.append(ch); } return result.toString(); } public String decode(String word) { StringBuilder result = new StringBuilder(); for (int i = word.length()-1;i >=0; i --) { char ch = word.charAt(i); ch = determineCharacter(ch, Constants.DECODE_SHIFT); result.append(ch); } return result.toString(); } public char determineCharacter(char ch, int shift) { if(Character.isLowerCase(ch) || Character.isUpperCase(ch)) ch = (char)('a' + (ch - 'a' + shift) % Constants.WRAP_AROUND); return ch; } }package assignment2; public class Reverser extends Transpose { Reverser(String s) { super(s); } String reverseText(String word) { StringBuilder result = new StringBuilder(); for (int i = word.length()-1;i >=0; i --) { char ch = word.charAt(i); ch = determineCharacter(ch, Constants.DECODE_SHIFT); result.append(ch); } return result.toString(); } }