Do not use your own computel, us A text file \"mywords.txt\" contains following
ID: 3910341 • Letter: D
Question
Do not use your own computel, us A text file "mywords.txt" contains following data (see below), we need to read this file, encrypt using a given cipher/cypher, and write the encrypted data to another data file called "output.txt". A cipher/cypher is a secret algorithm or code to encrypt data. The cypher for your encryption algorithm is to concatinate string 'd' after every odd character position and String "en" after every even character position on the reverse order of the original character set in a String. Consider the first character of the reverse order as position 1 rather than 0. Write a program to accomplish this encryption. (25 points) myword.txt should contain following words, copy and paste them to your text file. boutiques toxicologic periphrastically phew scorper scenarioization alterman locris Trun in a printed copy of your program and your output file. Do not print the input file.Explanation / Answer
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Driver {
public static String reverse(String str){
StringBuilder sb=new StringBuilder(str);
sb.reverse();
return sb.toString();
}
public static void main(String[] args) throws IOException{
BufferedReader b = new BufferedReader(new FileReader("mywords.txt"));
BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt"));
String line = "";
while((line = b.readLine()) != null) {
int count = 1;
String result = "";
for(int i = line.length() - 1; i >=0 ; i--) {
if(count % 2 == 1)
result += String.valueOf(line.charAt(i)) + String.valueOf('d');
else
result += String.valueOf(line.charAt(i)) + "en";
count++;
}
bw.write(reverse(result) + " ");
}
b.close();
bw.close();
}
}
**Comment for any further queries.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.