Cipher 

Requirements:

Create a Cipher program to: 


CodeSnipets:

   //Randomize character string to use as Key

List<Character> looneytoons = new ArrayList<Character>();

        for(int i='a'; i<='z'; i++)

            looneytoons.add((char)i);

        Collections.shuffle(looneytoons);



      //Generate Substitution Table

        Map<Character, Character> substitutionTable = new HashMap<Character, Character>();

        int listIndex = 0;

        for(int i='a'; i<='z'; i++)

            substitutionTable.put((char)i,looneytoons.get(listIndex++));

        substitutionTable.put(' ' , ' ');



        

     public static String encrypt(Map<Character,Character> swapTable, String plaintext){

        StringBuilder sb = new StringBuilder();

        for(char character : plaintext.toCharArray())

            sb.append(swapTable.get(character));

         String encrypted = sb.toString();

        return encrypted;

     }

   

     public static String decrypt(Map<Character,Character> swapTable, String encrypted){

        Map<Character,Character> swapTableInversed = swapTable.entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));

        StringBuilder sb2 = new StringBuilder();

        for(char character : encrypted.toCharArray())

            sb2.append(swapTableInversed.get(character));

        String decrypted = sb2.toString();

        return decrypted;

     }



Steps

//Generate swap Table

//Print swap table

//Request String to Encrypt

//Encrypt

//Decrypt

//Save EncryptKey to File

//Save initial phrase to File

//Save Encrypted String to File

 

//Method for

//Create encrypted string

// Process to decrypt selected string