I'm working on encrypted text using ascii value and I have this code:
import java.util.*;
public class OneTimePad{
public static void main(String[] args){
Scanner _user_ = new Scanner(System.in); //Scanner Obj
System.out.print(" Enter your Message : ");
String Message = _user_.next();
System.out.print(" Enter your Key : ");
String Key = _user_.next();
char Fnal;
int Total;
for(int l = 0 , m = 0; (l < Message.length() && m < Key.length()); l++,m++){
Total = (int)Message.charAt(l) + (int)Key.charAt(m);
if((Total >=65 && Total <= 90) || (Total >= 97 && Total <=122 )){
System.out.print("Case 1");
Fnal = (char)Total;
System.out.print(Fnal);
}else{
System.out.print("Case 2");
int a = Total % 26;
Fnal = (char)a;
System.out.print(Fnal);
}
}
}
}
Here is my output:
Enter your Message : hello
Enter your Key : hihih
Why only this two lines are printed on console? I don't see any error.
UPDATE
Here's my new code:
for(int l = 0 , m = 0; (l < Message.length() && m < Key.length()); l++,m++) {
Total = (int)Message.charAt(l) + (int)Key.charAt(m);
//char s = Message.charAt(l);
char dos = Message.charAt(l);
String comp = String.valueOf(dos);
if (comp.contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ")){
if(Total >=65 && Total <= 90){
Fnal = (char)Total;
System.out.print(Fnal);
}else{
int a = Total % 26 + 65 ;
Fnal = (char)a;
System.out.print(Fnal);
}
}
}
Why it didn't Working?