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);

    }
}

Comments

Popular posts from this blog

Missionaries & Canibal Problem in AI using Pro Log

Hide the navigation bar in jHipster Angular 2

Spring Boot - No Need to Restart the Development Server for Each Time