How to code the encryption code in java using a For loop statement?
November 9, 2009 - 12:48 am
I want to write a character encryption program that has to take an input,encrypt it and display the encrypted output.
Hint: A = @
B = a
C = b
D = c
E = d
eg: input = Hello World
output = gdkkn vnqkc
import org.apache.commons.lang.StringUtils;
public class Test {
public static void main(String[] args) {
String s = "Hello World";
StringBuffer output = new StringBuffer();
s = StringUtils.lowerCase(s);
for (int i=0; i < s.length() ; i++){
char c = s.charAt(i);
int charCode = (int) c;
charCode–;
output.append((char) charCode);
}
System.out.println("Output = " + output);
}
}
November 9th, 2009 at 6:21 am
import org.apache.commons.lang.StringUtils;
public class Test {
public static void main(String[] args) {
String s = "Hello World";
StringBuffer output = new StringBuffer();
s = StringUtils.lowerCase(s);
for (int i=0; i < s.length() ; i++){
char c = s.charAt(i);
int charCode = (int) c;
charCode–;
output.append((char) charCode);
}
System.out.println("Output = " + output);
}
}
References :