Question
Write a Java program to encode the plain text file (attack.txt) as cipher text based on a key value provided by the user. The cipher
Write a Java program to encode the plain text file (attack.txt) as cipher text based on a key value provided by the user. The cipher text once encoded should be written to a file named encoded.txt. Make sure the cipher text is outputted line by line to the output file such that the first line encoded from attack.txt is the first line in the file named encoded.txt.The 2nd line from attack.txt should be used to create the cipher text on line 2 of the encoded.txt file, and etc.
To do the encoding, create a recursive method named encode(String s, int key, int n) that takes a plain text String of length n and encodes it to a new cipher based String by adding the key value to each alphabet character in the plain text String. You should define a helper method so the caller only has to pass the String and key to the encode method.
For example, if the plain text String is attack at dawn and key is 5, it should be encoded as fyyfhpefyeifas because in the ASCII chart:
a+ 5 = f, t + 5 = y, c + 5 = h, k + 5 = p, + 5 = e, d + 5 = i, w + 5 = a, and n + 5 = s.
The String s accepted as a parameter for the encode method should be a line of text you retrieve from the plain text file given to you.
The encode method will return the encoded String to the caller so it can be written to the output file. The main method should be outputting the encoded text line by line to a text file of your choice.
Contents of attack.txt:
attack at dawn bring the big guns do not back down we are counting on you
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started