I have a program that accepts an input file, an output file, and an encryption key from the user.
The program uses the key from the user to encrypt the input file and writes the encryption to the output file.
I keep getting an array out of bounds error at line 13. How do i fix it?
The program uses the key from the user to encrypt the input file and writes the encryption to the output file.
I keep getting an array out of bounds error at line 13. How do i fix it?
import java.lang.String; import java.io.*; public class MonoCipherTester { public static void main(String[] args) throws Exception { String alphabets="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String replacestr; String inputString=args[1]; //line 13 inputString=inputString.toUpperCase(); String fname=args[2]; inputString = inputString.replaceAll((String.format("(.)(?<=(?:(/>/>?=\\1).).{0,%d}(?:(/>/>?=\\1).))",inputString.length())), ""); replacestr=inputString; System.out.println(alphabets); for(int i=25;i>=0;i--) { replacestr +=alphabets.charAt(i); } replacestr = replacestr.replaceAll((String.format("(.)(?<=(?:(/>/>?=\\1).).{0,%d}(?:(/>/>?=\\1).))",replacestr.length())), ""); System.out.println(replacestr); try { FileInputStream fstream = new FileInputStream(fname); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; String Data=""; //Read File Line By Line while ((strLine = br.readLine()) != null) { Data=Data+strLine; // Print the content on the console System.out.println (strLine); } Data=Data.toUpperCase(); if(args[0].equalsIgnoreCase("-k")) { for(int i=0;i<26;i++) { Data=Data.replace(alphabets.charAt(i),replacestr.charAt(i)); } System.out.println(); System.out.println(Data); } else if(args[0].equalsIgnoreCase("-d")) { for(int i=0;i<26;i++) { Data=Data.replace(replacestr.charAt(i),alphabets.charAt(i)); } System.out.println(); System.out.println(Data); } BufferedWriter out = new BufferedWriter(new FileWriter(args[3])); out.write(Data); out.close(); //Close the input stream in.close(); } catch(IOException exception) { System.out.println(""+ exception); } } }