Friday, January 31, 2020

Encryption and Decryption using well known Caeser Cipher technique in java.... 


class Caeser
{
public static void main(String arg[])
{
String pt="Coding Adda by TALWINDER Mann";
int key = 9;
System.out.println(" Plain Text - "+pt);
String ct =enc(pt,key);
System.out.println(" after Encryption Cipher Text - "+ct);
String cpt= dec(ct,key);
System.out.println(" after Decryption Plain Text - "+cpt);
}
        public static String enc(String pt, int key)   // Encryption 
{
String ct="";
char c;
for(int i=0; i<pt.length(); i++)
{
c = pt.charAt(i);
int ascii= c;
if(ascii>96 && ascii<124)
{
int tt= (ascii+key-97)%26+97;
ct=ct+(char)tt;
  }
if(ascii>64 && ascii<92)
{
int tt= (ascii+key-65)%26+65;
ct=ct+(char)tt;
  }
}
return ct;
}
public static String dec(String ct, int key)  //Decryption... 
{
String pt="";
char c;
for(int i=0; i<ct.length(); i++)
{
c = ct.charAt(i);
int ascii= c;
if(ascii>96 && ascii<124)
{
int tt= ((ascii+26) - 97-key)%26+97;
pt=pt+(char)tt;
  }
if(ascii>64 && ascii<92)
{
int tt= ((ascii+26)- key-65)%26+65;
pt=pt+(char)tt;
  }
}
return pt;
}
}



No comments:

Post a Comment

Write a program in python which determine determines that the number is prime or not. What is your favorite number?

Write a program in python which determine determines that the number is prime or not. What is your favorite number? Code   number = int(inpu...