Saturday, February 9, 2019

ISC practical caesar cipher(2017)

ISC practicals solved
This question was asked in ISC practical 2017.
Caesar cipher is a encryption technique that is used to prevent the unauthorised use of data.
It is used to convert information into a secret code.it is implemented as ROT13(rotate by 13 places).
          eg Hello!How are you?
          /---- Uryyb? Ubj net lbh?

 import java.util.*;
import java.io.*;
public class encrypted
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
String st=in.nextLine();
String dup="";
char c=65;
int i,j,length,place,ass;
length=st.length();
if(length<3)
{
System.out.println("invalid lengtg");
}
else
{  i=0;
while(i<length)
{   c=st.charAt(i);
place=st.charAt(i);
if((place>=65)&&(place<=90))
{
place=place+13;
if(place>90)
{
ass=place-90;
place=65+ass-1;

}
c=(char)place;
}
else if((place>=97)&&(place<=122))
{
place=place+13;
if(place>122)
{
ass=place-122;
place=97+ass-1;

}
c=(char)place;
}
else if(c=='!'){
c=st.charAt(i);
place=c+13;
c=(char)place;}
dup=dup+c;

i++;}
}
System.out.println("the encrypted text is ="+dup);

}
}

No comments:

Post a Comment