Caesar Cipher Encription & Decription

Can easily hide your text using this type of encription method
more : wiki

/* Encripting Part*/
public class Caserchiper{
   

    public void Encripter(String S, int j){
       
    for(int i=0; i<S.length(); i++){
        // get the paticular Character on the String
        char C = S.charAt(i);
        // Casting the value to integer
        int value = (int)C;
        // adding some intger
        int encrpt = value + j;
        // casting the encripted value to Character
        char encChar = (char)encrpt;
        System.out.print(encChar);
    }
    System.out.println();
    }
}

/*Decripting Part*/
public class CaserchiperDecripter{
   
    public void Decripter(String S,int j){
    for(int i=0; i<S.length(); i++){
        char C = S.charAt(i);
        int value = (int)C;
        int encrpt = value -j;
        char encChar = (char)encrpt;
        System.out.print(encChar);
    }
    System.out.println();

    }
}

/*Demo Class*/
import java.util.*;
public class Demo{
    public static void main(String args[]){
    Scanner S = new Scanner(System.in);
    System.out.println(“Enter your word to encript”);
    String word1 = S.next();
    System.out.println(“Enter the key”);
    int i = S.nextInt();
    Caserchiper C1 =new Caserchiper();
    C1.Encripter(word1,i);
    CaserchiperDecripter C2 = new CaserchiperDecripter();
    System.out.println(“Enter your word to desript”);
    String word2 = S.next();
    System.out.println(“Enter the key”);
    int j = S.nextInt();
   
    C2.Decripter(word2,j);

    }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s