Reputation:
I tried to bring back removed white space after encrypted string.
Enter Plain Text:hello world
Result : itssgvgkbsr
It should bring back the removed spaces into their actual places.Expected Output:
Result : itssg gkbsr
private static void EncryptionChiper(String plainText, String keyChiper){
char[] letter = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'r', 'x', 'y', 'z'};
char[] charKeyChiper = keyChiper.toCharArray();
System.out.print("Result : ");
for (int i = 0;i<plainText.length();i++){
for (int j = 0;j<letter.length;j++){
if(letter[j]==(plainText.charAt(i))){
System.out.print(charKeyChiper[j]);
}
}
}
}
System.out.print("Enter Plain Text:");String plainText = scan.nextLine();
System.out.print("Enter Key(26):");String key = scan.nextLine();
EncryptionChiper(plainText,key);
Upvotes: 1
Views: 108
Reputation: 466
Just add another if
case:
if(' '==(plainText.charAt(i))){
System.out.print(' ');
break;
} else if(letter[j]==(plainText.charAt(i))){
System.out.print(charKeyChiper[j]);
break;
}
Upvotes: 2