java - How can I use my encryption program to create a decryption program? -


how can convert encryption code used decryption? not want them in same program used in 2 different files. need figuring out how take parts of code use decryption code. need use code , find way use parts of create program decrypt codes created code below.

the code using encryption is:

import java.util.*;  public class cipher //this class encrpyt program {    public static char cipher (int j){ //this mehtod generates random letter     char[] cipher1 = {'a','b','c','d','e','f','g'}; //characters char array     j = (int) (math.random() * cipher1.length);//choose random element array     return cipher1[j]; //this return letter   } //end of cipher method    public static void main (string[] args){ //main method      system.out.print("please type sentence encrypted\n");//asks user word encrypted     scanner inputscanner = new scanner(system.in); //imports scanner reader     string userinput = inputscanner.next(); //assigns word entered user varible userinput     userinput = userinput.touppercase(); //userinput in transferred upper case letters     int yu = userinput.length(); //yu finds length of charceters in userinput     char[] chararray = userinput.tochararray(); //sends userinput chararray      int w=1; //used try catch block     system.out.println("please enter pattern"); //prompt pattern     string pattern = inputscanner.next(); //pattern decide how many characters input in encrypted code     int pattern2 = integer.parseint(pattern); //changes string value integer value      do{        try{ //try block catch if user enters letters or decimal numbers         w=2;         if(pattern2<0){           system.out.println("please enter number above 0"); //prompt if user enters somthing below 0           w=1;         }       }catch (numberformatexception f){         system.out.println("please enter number!"); //prompt if user enters user number       }      }while (w==1); //end of , try catch block      system.out.print("your encrypted code is: "); //prompt give user encrypted code      for(int = 0; < yu; i++){       system.out.print(chararray[i]);       for(int q = 0; q < pattern2; q++){         system.out.print( cipher(1));       } //end of loop     } //end of loop    } //end of main method } //cipher class 

no, code encyption only. code seems one time pad.

for decryption, need know reverse logic knowing how receiver knows changes have been made , how undo them. start reading theory behind practice :)


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -