Professional Documents
Culture Documents
Encryption
Encryption
Encryption
Date:11.8.2022
AIM:
To encrypt and decrypt the given message by using Ceaser Cipher encryption
algorithm.
ALGORITHM:
1. In a Ceaser Cipher each letter in a plaintext (or) message is replaced by
a letter some fixed number of positions down the alphabet.
2. For example, with a left shift of 3, D would be replaced by A, E would be
replaced by B and so on.
3. And it can be vice versa (up the alphabet).
4. Encrypt the letter in the message by checking its ascii value and replace it
by the letter which is 3 up to that letter in the alphabet.
5. Similarly decrypt the message by comparing the ascii values of letters in
encrypted message and replace it by letter which is 3 down in the
alphabet.
6. Display the encrypted and decrypted message.
PROGRAM:
import java.util.Scanner;
public class JavaApplication1 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
String s;
int p=0;
String temp="";
System.out.println("Enter the message:");
s=in.nextLine();
String str[]=s.split(" ");
String a[]=new String[str.length];
System.out.println("The encrypted message is: ");
for(String s1:str){
for(int j=0;j<s1.length();j++){
int c= (char)s1.charAt(j);
if((c>=97 && c<=119) || (c>=65 && c<=87) ){
int h=c+3;
temp=temp+ (char)h;
}
else if(c>119)
{
int h=c-23;
temp=temp+ (char)h;
}
}
System.out.print(temp+" ");
a[p]=temp;
p++;
temp="";
}
System.out.println();
System.out.println("The decrypted message is: ");
int f=0;
String w[]=new String[str.length];
for(String s1:a){
for(int j=0;j<s1.length();j++){
int c= (char)s1.charAt(j);
if((c>=100 && c<=122) || (c>=68 && c<=90) ){
int h=c-3;
temp=temp+ (char)h;
}
else if(c<100)
{
int h=c+23;
temp=temp+ (char)h;
}
}
System.out.print(temp+" ");
w[f]=temp;
f++;
temp="";
}
}
}
OUTPUT:
Observation(20)
Record(5)
Total(25)
Initial
RESULT:
Thus the program for ceaser cipher encryption and decryption algorithm has
been implemented and the output verified successfully.