In: Computer Science
The following methods are used: main(...), the encode(...) and the decode()....Is there any issue with one of the method? If yes can you correct it.
You are requested to implement the same program without the two methods encode() and decode()...
Implement the code only with the main() and test your program again.
public class SCiphM {
final static String key = "]kYV}(!7P$n5_0i
R:?jOWtF/=-pe'AD&@r6%ZXs\"v*N"
+
"[#wSl9zq2^+g;LoB`aGh{3.HIu4fbK)mU8|dMET><,Qc\\C1yxJ";
static String text = "Here we have to do is
there will be a input/source "
+ "file in which we are going to Encrypt the file by replacing
every "
+ "upper/lower case alphabets of the source file with another
"
+ "predetermined upper/lower case alphabets or symbols and save
"
+ "it into another output/encrypted file and then again convert
"
+ "that output/encrypted file into original/decrypted file. This
"
+ "type of Encryption/Decryption scheme is often called a "
+ "Substitution Cipher.";
public static void main(String[] args) {
String enc =
encode(text);
System.out.println("Encoded: " + enc);
System.out.println("\nDecoded: " + decode(enc));
}
static String encode(String s) {
String sb = new
String(s);
String r="";
for (int i =0 ; i <
sb.length(); i++) {
r= r + key.charAt((int)sb.charAt(i) - 32);
}
return r;
}
static String decode(String s) {
String sb1 = new
String(s);
String r1="";
for (int i =0 ; i <
sb1.length(); i++) {
r1= r1 + key.charAt((int)sb1.charAt(i) + 32);
}
return r1;
}
}