Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need it ASAP-Already have the answer to this question(Question and Answer posted) , I am looking for explanation and slight change to the Java program.

Need it ASAP-Already have the answer to this question(Question and Answer posted) , I am looking for explanation and slight change to the Java program.

Question posted previously:

Link- https://www.chegg.com/homework-help/questions-and-answers/please-write-java-program-need-hours-asap-show-work-per-requirementsextra-credit-best-answ-q31368132

Question-

Please write a java program - need it in few hours asap. Show all the work as per requirements.extra credit for best answer.

Vignere Cipher

In this assignment youll write a program that encrypts the alphabetic letters in a file using the Vignere cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below.

1.1 Command line parameters

1. Yourprogrammustcompileandrunfromthecommandline.

2. Input the required file names as command line parameters. Your program may NOT prompt the user to enter the file names. The first parameter must be the name of the encryption key file, as described below. The second parameter must be the name of the file to be encrypted, as also described below. The sample run command near the end of this document contains an example of how the parameters will be entered.

3. Yourprogramshouldopenthetwofiles,echotheprocessedinputtothescreen,makethe necessary calculations, and then output the ciphertext to the console (terminal) screen in the format described below.

Note

If the plaintext file to be encrypted doesnt have the proper number (512) of alphabetic

CIS3360 PA1 1

characters, pad the last block as necessary with the lowercase letter x. Make sure that all the input characters are lower case only.

1.2 Formats

1.2.1 Encryption Key File Formats

The encryption key is plain text that may contain upper and lower case letters, numbers, and other text. The input must be stripped of all non-alphabetic characters. Please note that the input text must be converted to contiguous lower case letters to simplify the encryption process.

1.2.2 Encryption Plaintext File Formats

The file to be encrypted can be any valid text file with no more than 512 letters in it. (Thus, it is safe to store all characters in the file in a character array of size 512, including any pad characters.) Please note that the input text file will also generally have punctuation, numbers, special characters, and whitespace in it, which should be ignored. You should also ignore whether a letter is uppercase or lowercase in the input file. Thus, you should treat A and a the same in your program. In order to simplify the encryption, all letters should be converted to lower case letters. In the event the plaintext input file is less than 512 characters, pad the input file with a lowercase x until the 512 character input buffer is full.

1.2.3 Output Format

The program must output the following to the console (terminal) screen, also known as stdout:

1. Echothelowercasealphabetictextderivedfromtheinputkeyfile.

2. Echothelowercasealphabetictextderivedfromtheinputplaintextfile.

Remembertopadwithxiftheprocessedplaintextislessthan512characters.

3. Ciphertextoutputproducedfromencryptingtheinputkeyfileagainsttheinputplaintext

file.

The output portion of each input file should consist of only lowercase letters in rows of exactly 80 letters per row, except for the last row, which may possibly have fewer. These characters should correspond to the ciphertext produced by encrypting all the letters in the input file. Please note that only the alphabetic letters in the input plaintext file will be encrypted. All other characters should be ignored.

1.3 Submission instructions

You must submit this assignment in Webcourses as a source file upload. Note that all submissions will be via Webcourses. The submitted programs will be tested and graded on Eustis.

Make sure to include a comment at the top of your main source file that contains the following Academic Integrity statement (substitute your name and NID) - I [name] ([NID]) affirm that this program is entirely my own work and that I have neither developed my code together with any another person, nor copied any code from any other person, nor permitted my code to be copied or otherwise used by any other person, nor have I copied, modified, or otherwise used programs created by others. I acknowledge that any violation of the above terms will be treated as academic dishonesty.

1.4 Program Notes and Hints

Your program must read in an input plaintext file that may contain uppercase letters, lowercase letters and non-letter characters. Your program must distinguish between these three groups so that only the letters get encrypted. All non-letter characters in the file are simply skipped and not counted as part of the plaintext. Please note that although both upper case and lower case letters will be encrypted, your program should convert an upper case input letter to the corresponding lower case letter, i.e., it should convert an A to an a, and so on for the whole alphabet.

One possible breakdown to solve this problem is as follows:

1. Writeasectionofcodeorfunctionthatreadsonlytheupperandlowercaselettersinthe input file into an char array of size 512, storing only the appropriate lowercase letters in the character array.

2. Write a section of code or function that takes as input the array from section 1 and the encryption key and produces an array of ciphertext storing only lowercase letters.

3. Write a section of code or function that takes as input the array storing the ciphertext and outputs it to the screen in the format specified. Additional functions or code will be needed to echo the input key and plaintext files.

1.5 Sample inputs and outputs

1.5.1 Sample Key File

I think and think for months and years. Ninety-nine times, the conclusion is false. The hundredth time I am right. - Albert Einstein Imagination is more important than knowledge. For knowledge is limited, whereas imagination embraces the entire world, stimulating progress, giving birth to evolution. - Albert Einstein1

1.5.2 Sample Plaintext File

Fall in love with some activity, and do it! Nobody ever figures out what life is all about, and it doesnt matter. Explore the world. Nearly everything is really interesting if you go into it deeply enough. Work as hard and as much as you want to on the things you like to do the best. Dont think about what you want to be, but what you want to do. Keep up some kind of a minimum with other things so that society doesnt stop you from doing anything at all. - Richard Feynman2

1.5.3 Sample Ciphertext Output File

ntstvxlbyxdqgrxcdqopmpnigbyrdugvbasumqgrzxzrmynyiuchvhbsbzvnwnsldptisbnnqumwwvxa

zxuafkmxlqpwpvvmlmjgkplammrrgrvxzmgpazuzwzqpzcriamxyefdvbctjbuylczxgceehhkttqpva

czlzkyorwhszpatlnsfcqueezfuyefmassampvxdwervqhcxcvemwquiyshvwlvuvobuoosruvnhacoe

shcknneussxfcgoaeblwndiadtbghrmrzzdjaardpfdbiyqieazczabruwglxzflagnwucgjlnkwqvml

ddzwwgawaicbfyikvflamvgmegzobnrbxrepzvuaezqnqytunnqflkfpjlobfjmloqxkqqexkhkltiba

dbclohkltibadbfpifjfqbatebobxpfjxdfkxqflkbjyoxzbpqebbkqfobtloiapqfjrixqfkdmoldob

ppdfsfkdyfoqeqlbslirqflkxiyboqbf

Scoring will be based on the following rubric:

Table 1.1: Grading Rubric

Deduction

Description

-100

Cannot compile on eustis

-100

Your program does not successfully compile from the command line with one of these commands:

Cprogram:

C++ program:

Java program:

Note:

If you are submitting a Java program, the class file must be named vigenere.java and the class name must be vigenere.

prompt$gcc -o vigenere vigenere.c

prompt$g++ -o vigenere vigenere.cpp

prompt$javac vigenere.java

-100

Cannot read input files specified on command line

-100

Cannot write output to stdout

-90

Your program does not run from the command line without error or produces no output.

-70

The program compiles, runs, and outputs the key matrix and input file, but crashes thereafter or produces no encryption output.

-50

Runs without crashing but produces no meaningful encryption output

-20

Fails to produce valid all lowercase alphabetic key

-20

Fails to produce valid all lowercase alphabetic plain text

-20

Fails to produce valid lowercase alphabetic ciphertext - formatted to 80 columns per line

-25

Does not have Academic Integrity statement

Start with 100 points and deduct per the schedule above

----------------------------------------------------------------------------------------------------------------------

Answer provided by chegg is below-

import java.io.*;

class VigenereCipher{

int size = 512;

public String encrypt(String plainText , String key){

char textChar;

char keyChar;

String encrptedText = "";

int keyLength = key.length();

for (int i = 0, j = 0; i < plainText.length(); i++)

{

textChar = plainText.charAt(i);// getting charcter of plainText

keyChar = key.charAt(j); // getting character of key

//ASCII value for 'a' is 97. Formula to get vigenere cipher text

encrptedText += (char)((textChar + keyChar - 2 * 97) % 26 + 97);

// updating j value if it is equal to key length then make it 0.

j = ++j % keyLength;

}

return encrptedText;

}

}

class vigenere {

public static void main(String args[]) {

String key = "";

String str = "",plainText = "";

String fstr;

try

{

// Reading key file

File file = new File("E:\\key.txt");

BufferedReader br = new BufferedReader(new FileReader(file));

while ((fstr = br.readLine()) != null)

{ //using regex expression to remove non-alphabetic characters

//and convert them to lower case.

key += fstr.replaceAll("[^A-Za-z]", "").toLowerCase();

}

// Reading plain text file

file = new File("E:\\plaintext.txt");

br = new BufferedReader(new FileReader(file));

while ((fstr = br.readLine()) != null) {

str += fstr.replaceAll("[^A-Za-z]", "").toLowerCase();

}

// If plain text file length grater than 512 then truncate data.

if(str.length()>512){

plainText = str.substring(0,512);

}

// else if less than 512 then add padding x

else if(str.length() < 512)

{

while(true){

if(str.length()==512)

break;

str += "x";

}

plainText = str;

}

VigenereCipher cipher = new VigenereCipher();

String encrptText = cipher.encrypt(plainText, key);

//print data 80 characters per line

for(int i=0; i< encrptText.length() ; i=i+80)

System.out.println(encrptText.substring(i, Math.min(encrptText.length(),i+80)));

}

catch(Exception ex){

//System.out.println("File Not Found");

}

}

}

---------------------------------------------------------------------------------

I have recieved a comment from professor

" This program has issue accepting command line arguments , can you please check on this and correct it ?"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

5-8 What are the advantages and disadvantages of the BYOD movement?

Answered: 1 week ago