Hello I am trying to design a system in java that will acceptcommand line argume
ID: 3612530 • Letter: H
Question
Hello I am trying to design a system in java that will acceptcommand line arguments on a UNIX box. Rapunzel, I saw you're otherpost on here where you helped design a similar system, howeverthere are a few adjustment's I'm looking for. Instead of beingprompted to enter a key, i'd like the program to be run on a UNIXbox as follows. Once compiled...java -e KEY plaintext.txt cipher.txt
When this is executed on the UNIX shell, the plaintext file will beread, encrypted and sent to another text file, say cipher.txt withthe encrypted message.
Then if the user wants to decrypt:
java -d KEY cipher.txt plaintext2.txt
When this is executed on a UNIX shell the cipher.txt will be read,decrypted, and sent to a new plaintext file with the decryptedmessage.
Could you please help me make these adjustments?
Once more here are the specs of how the encryption shouldwork:
The idea is to use substitution based encryptionusing the following information.
Input alphabet = {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z} (26symbols)
Output alphabet = Letters + Numbers; where:
Letters = {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z};
Numbers = {0,1,2,3,4,5,6,7,8,9} (a total of 26 + 10 = 36symbols)
Substitution method:
(1) The parties agree on a secret word, whose length is between 5and 26 symbols taken from the Letters set. Let us call thisword the KEY. The secret word must be such that no symbols ofLetters are repeated in it. (For instance, KEY = ANALYSISwould not satisfy this property.)
(2) The sender generates a random number between 1 and 26. Let uscall this number n.
(3) The sender aligns the secret word KEY under the n-th characterof Input alphabet (depending on the length of KEY, wrap-aroundmight be needed)
(4) All remaining symbols in Input alphabet are substituted bythe symbols in Letters which are not in KEY, in the order theyappear in Letters.
Thank you very much I look forward toyour reply!
Explanation / Answer
please rate -thanks hope this helps with the adjustments import java.io.*; import java.util.*; public class untitled { public static void main(String[] args) throws FileNotFoundException { if(args[0].equals("-e")) encrypt(args[1],args[2],args[3]); else if(args[0].equals("-d")) decrypt(args[1],args[2],args[3]); else System.out.println("invalidoption"); } public static void encrypt(String key,String file1, String file2)throws FileNotFoundException { Scanner input=new Scanner(new File(file1)); PrintStream out=new PrintStream(new File(file2)); System.out.println("in encrypt"); input.close(); out.close(); } public static void decrypt(String key,String file1, String file2)throws FileNotFoundException { Scanner input=new Scanner(new File(file1)); PrintStream out=new PrintStream(new File(file2)); System.out.println("in decrypt"); input.close(); out.close(); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.