Implementation of POLYALPHABETIC SUBSTITUTION CIPHER usin java(Encryption technique)


Steps

  1. Select Java form the categories and Java Application  from the projects, click Next.
  2. Set the Project name as  PolyCiipher  and set the Create Main Class, click Finish.
  3. Under the  project "polyciipher", you can see two files, double click the Source Packages,you can see a package by name polyciipher " ,double click it you will find the Java Main Class FilePolyCiipher.java.
  4. Open this file, remove the existing code and paste the following code.
------------------------------------------PolyCiipher.java.---------------------------------------------------------


package polyciipher;
import java.util.*;

/**
 *
 * @author ZISSAN
 */
public class PolyCiipher {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     int[] j =  new int[100];
        int[] s = new int[100];
        String test="";
        // initialization of the Scanner class,handles input from user,can be found in the java.util.*; library.
        // we are creating object "in" from the scanner and telling java that this will be System input
        try{
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the plain text(STRING SHOULD BE IN UPPERCASE AND DONT GIVE SPACE BETWEEN WORDS)::");
        // next() is a method which  gets the next string of text that a user types on the keyboard
        test = in.nextLine();
        for ( int i = 0; i < test.length(); ++i ) {
       char c = test.charAt( i );// "c" holds the individual character of the string
       s[i] = (int) c-65;          
       
       }
       for(int i=0;i<test.length()-1;i++){
       j[i+1]=s[i];
       } 
        System.out.println("Enter the key::");
        int k = Integer.parseInt(in.nextLine());
        j[0]=k;
       System.out.println();    
       System.out.println("The position of the character in the cipher text::");
        for(int i=0;i<test.length();i++){
        j[i]=j[i]+s[i];
        j[i]=j[i]%26;
        System.out.print(j[i]);
        }
        System.out.println();
        System.out.println("The cipher text::");
        for(int i=0;i<test.length();i++){
        char c=(char) (j[i]+65);
        System.out.print(c);
        }
        System.out.println();
        }
        catch(Exception er){
        System.out.println("--YOU HAVE TYPE INVALID DATA--");
        }   
    }
}
----------------------------------------------------------output---------------------------------------------------------------

run:
Enter a string(STRING SHOULD BE IN ASCII AND DONT GIVE SPACE BETWEEN WORDS)::
ATTACKISTONIGHT
Enter the key::
12

1219121921218011712114130
MTMTCMSALHBVONA
BUILD SUCCESSFUL (total time: 16 seconds)


No comments:

Post a Comment