Question: Question #B . 1 Create a new Java class, and call it XOREncryption. You will need to import one Java package in order to work

Question #B.1
Create a new Java class, and call it XOREncryption.
You will need to import one Java package in order to work with File objects. What is it?(If you are not sure, consult the Java 8 documentation for File.) Import this package before your class definition.
Question #B.2
Download the data.txt file, and save it in the same folder as your XOREncryption class. Open up the text file - do you recognize this text? (Who said it, and on what occasion?) Create a new .txt file named key.txt that has the following text: This is a key
Question #B.3
The File constructor takes a String as a parameter, which represents a file path. In your main method, create two File objects, one for each of your .txt files. (Because you put the .txt files in the same folder as your Java class, you can use relative file path.)
Question #B.4
When you use a method that is new to you, it is a good practice check if it throws any exceptions - if it throws a checked exception, you need to handle it or your code will not compile! In the Java documentation, you can click on a method to see additional details; this will show you which exceptions are thrown.
Name two common unchecked exceptions, and their parent class. Name two common checked exceptions, and their parent class. How can you tell if an exception is checked or unchecked?
Question #B.5
Now, you need to be able to read from each of your File objects. To do this, you will use the FileInputStream class. Open up the Java 8 docs for FileInputStream. Find the constructor that takes a File object as a parameter. What exception does this constructor throw? Is this a checked or unchecked exception? If this is a checked exception, make sure to put it in a try-catch block, and handle it by printing "No file." to the console.
Compile your code.
Question #B.6
The read method of the FileInputStream class requires an initialized byte array for its parameter. Create and initialize two byte arrays, one for each FileInputStream object. To determine the length of each byte array, you can use the length method of FileInputStream. (Be careful, because this method returns a long, not an int.)
After initializing the byte arrays, call the read method on each FileInputStream object, and pass in each byte array as a parameter.
Make sure to handle any exceptions thrown by read or length.
Part C: Implementing the XOR Algorithm
To implement the algorithm, you will need to iterate over each byte in the byte array created from the data.txt file.
Question #C.1
For each byte in the data. txt file array, you should find the index of the key byte array by taking the for-loop counter mod the length of the key byte array. Then, encrypt the byte: (byte at the for

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!