/**Driver
  *
  */


import java.util.Scanner;
import java.io.File;
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class Driver{

/**Main driver to open files
  *
  *@param args[]   Holds command line arguments: filename.
  */
 public static void main(String[] args) throws Exception {
   String inputFile = "";
   String outputFile = "";
   Boolean compress = false;
   Boolean extract = false;
   Boolean encrypt = false;
   Boolean decrypt = false;

   ArrayList<String> text = new ArrayList<String>();
   ArrayList<String> outText = new ArrayList<String>();

   for (int i=0; i<args.length; i++) {
     String inputArg = args[i];

     switch (inputArg) {
       case "--help":
       case "-h":
        System.out.println("Usage: ");
        System.out.println("--help, -h: Print this helpfile and exit.");
        System.out.println("--input, -i: Filename to read input text from.");
        System.out.println("--output, -o: Filename to send output to.  If omitted, STDOUT will be used.");
        System.out.println("--compress, -c: Flag to run compression algorithm.");
        System.out.println("--extract, -x: Flag to decompress the text.");
        System.out.println("--encrypt, -e: Flag to encrypt the text.");
        System.out.println("--decrypt, -d: Flag to decrypt the text.");
        return;

       case "--input":
       case "-i":
        inputFile = args[i+1];
        break;

       case "--output":
       case "-o":
        outputFile = args[i+1];
        break;

       case "--compress":
       case "-c":
        compress = true;
        break;

       case "--extract":
       case "-x":
         extract = true;
         break;

       case "--encrypt":
       case "-e":
        encrypt = true;
        break;

       case "--decrypt":
       case "-d":
        decrypt = true;
        break;
     }
   }

   //Exit if invalid flags are supplied.
   if (compress & extract) {
     System.out.println("Incompatible arguments supplied: --compress, --extract");
     return;
   }

   if (encrypt & decrypt) {
     System.out.println("Incompatible arguments supplied: --encrypt, --decrypt");
   }

   // Read input file
   if (inputFile != "") {
     File buffer = new File(inputFile);
     if (buffer.exists() && !buffer.isDirectory()) {
       text = ReadFile(inputFile);
     } else {
       System.out.println("Input file not found on disk: " + inputFile);
     }
   }


   // begin compression
   if (compress | extract) {
     HuffmanTranslator translator = new HuffmanTranslator();
     translator.buildEncoderTree();

     for (int i=0; i<text.size(); i++) {
       if (compress) {
         String newString = translator.encode(text.get(i));
         outText.add(newString);
       } else if (extract) {
         String newString = translator.decode(text.get(i));
         outText.add(newString);
       }
     }

   }

   //Output information: either to stdout or a filename
   if (outputFile != "") {
     System.out.println("#-----------------------#");
     System.out.println("Writing file " + outputFile);
     System.out.println("#-----------------------#");
     WriteToFile(outText, outputFile);
   } else {
     System.out.println("No output file supplied, redirecting to STDOUT");
     for (int i=0; i<outText.size(); i++) {
       System.out.println(outText.get(i));
     }
   }

 }

 private static ArrayList ReadFile(String filename) throws java.io.FileNotFoundException {
   Scanner scanner = new Scanner(new File(filename));

   ArrayList<String> words = new ArrayList<String>();

   System.out.println("#-----------------------#");
   System.out.println("Reading file " + filename);
   System.out.println("#-----------------------#");

   while(scanner.hasNext()){
     words.add(scanner.next());
   }

   return words;
 }

 private static void WriteToFile(ArrayList text, String outName) {
   PrintWriter pw = null;

   try {
      File file = new File(outName);
      FileWriter fw = new FileWriter(file, true);
      pw = new PrintWriter(fw);

      for (int i=0; i<text.size(); i++) {
        pw.println(text.get(i));
      }

   } catch (IOException e) {
      e.printStackTrace();
   } finally {
      if (pw != null) {
         pw.close();
      }
   }
 }

}

@@ -171,16 +171,80 @@
 rayList;
+%0Aimport java.util.regex.Pattern;%0Aimport java.util.regex.Matcher;
 %0A%0Apublic
@@ -699,75 +699,265 @@
 %0A   
-for (int i=0; i%3Cargs.length; i++) %7B%0A     String inputArg = args%5Bi%5D;
+// regex pattern match for encryption%0A   Pattern p = Pattern.compile(%22%5E(-%7B1,2%7D%5Ba-z%5D+)%5B0-9%5D+$%22);%0A%0A   for (int i=0; i%3Cargs.length; i++) %7B%0A     Matcher m = p.matcher(args%5Bi%5D);%0A     String inputArg = %22%22;%0A     if (m.find()) %7B%0A       inputArg = m.group(1);%0A     %7D
 %0A%0A  
@@ -2025,16 +2025,377 @@
 e %22-e%22:%0A
+        Pattern e_pattern = Pattern.compile(%22%5E-%7B1,2%7D%5Ba-z%5D+(%5B0-9%5D+)$%22);%0A        Matcher e_match = e_pattern.matcher(args%5Bi%5D);%0A        Integer shift_val = 0;%0A        //String shift_val = %220%22;%0A        if (e_match.find()) %7B%0A          shift_val = Integer.parseInt(e_match.group(1));%0A        %7D%0A        System.out.println(%22Found simple shift of value %22 + shift_val);%0A%0A
         

Modify driver to accept simple encryption shift