Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I apologize for not copy and pasting the code. Something is wrong with my comput

ID: 669397 • Letter: I

Question

I apologize for not copy and pasting the code. Something is wrong with my computer, so I'm having to use my phone. I just don't know how to save the data to a secondary file. I've tried using PrintWriter, but that hasn't worked. This is my code so far:
should be read from the file and stored in e Demonstrate both methods in a program. ments: the nalme ur a m File encryption is the science of writing the contents of a file in a secret code. Your tion program should work like a filter, reading the contents ot one file, modifying the yP into a code, and then writing the coded contents out to a second file. The second file a version of the first file, but written in a secret code. e. Your encryp- ying the da il cret code. Your encr 7. File Encryption Filter e second file w e will be Although there are complex encryption techniques, you should come up with a simple of your own. For example, you could read the first file one character at a time, and add to to the character code of each character before it is written to the second file. e one one 8. File Decryption Filter Write a program that decrypts the file produced by the program in Programming Challenge 7. The decryption program should read the contents of the coded file, restore the data to its original state, and write it to another file. d by the program in Programming Challenge 7 and wrtesto r h etets file, restore the data to a

Explanation / Answer

Correct version of the program:


package cyphercreator;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;


public class CypherCreator {


public static void main(String[] args) throws IOException{
Scanner keyboard=new Scanner(System.in);
int key;
System.out.println(" Secret cypher creator");
System.out.println(" This program will encrypt or decrypt the file of your choice");
System.out.println(" To encrypt a file press positive integer.To encrypt a file press negative integer:");
System.out.println(" Enter a number between 0 to 25 to encrypt or decrypt the file:");
key=keyboard.nextInt();
try{
//String filename="input.txt";
//File ff=new File("newIinput.txt");
File ff = new File("C:\Users\Sangeetha\Desktop ewInput.txt");
File file=new File("C:\Users\Sangeetha\Desktop ewOutput.txt");
// if file doesnt exists, then create it
           if (!file.exists()) {
               file.createNewFile();
           }


PrintWriter alteredFile = new PrintWriter(file);


String answer="";
try (Scanner data = new Scanner(ff)) {
while(data.hasNextLine())
{
String s=data.next();
System.out.println(" data:"+s+" ");
int clear;
char cipher;
int i=0;
char lowerCase;
char upperCase;
lowerCase=(char)((25-key)+'a');
upperCase=(char)((25-key)+'A');
while(i<s.length())
{
if(s.charAt(i)>='a' && s.charAt(i)<=lowerCase)
{
clear=s.charAt(i)+key;
cipher=(char)clear;
System.out.print(cipher);
answer=answer+""+cipher;
}
else if(s.charAt(i)>=lowerCase && s.charAt(i)<='z')
{
clear=s.charAt(i)-(26-key);
cipher=(char)clear;
System.out.print(cipher);
answer=answer+""+cipher;
}
else if(s.charAt(i)>='A' && s.charAt(i)<=upperCase)
{
clear=s.charAt(i)+key;
cipher=(char)clear;
System.out.print(cipher);
answer=answer+""+cipher;
}
else if(s.charAt(i)>upperCase && s.charAt(i)<='Z')
{
clear=s.charAt(i)-(26-key);
cipher=(char)clear;
System.out.print(cipher);
answer=answer+""+cipher;
}
else
{
System.out.print(s.charAt(i));
answer=answer+""+s.charAt(i);
}
i++;
  
}
alteredFile.print(answer);
alteredFile.flush();
}
}
System.out.println("The data is saved in altered file. Use Note pad to open");
}
catch(FileNotFoundException e)
{
System.out.println(e);
}
}
  
}

input file:newInput.txt

cypher (third-person singular simple present cyphers,
present participle cyphering,
simple past and past participle cyphered).

output file:newOutput.txt

dzqifsdzqifs(uijse-qfstpodzqifs(uijse-qfstpotjohvmbsdzqifs(uijse-qfstpotjohvmbstjnqmfdzqifs(uijse-qfstpotjohvmbstjnqmfqsftfoudzqifs(uijse-qfstpotjohvmbstjnqmfqsftfoudzqifst,dzqifs(uijse-qfstpotjohvmbstjnqmfqsftfoudzqifst,qsftfoudzqifs(uijse-qfstpotjohvmbstjnqmfqsftfoudzqifst,qsftfouqbsujdjqmfdzqifs(uijse-qfstpotjohvmbstjnqmfqsftfoudzqifst,qsftfouqbsujdjqmfdzqifsjoh,dzqifs(uijse-qfstpotjohvmbstjnqmfqsftfoudzqifst,qsftfouqbsujdjqmfdzqifsjoh,tjnqmfdzqifs(uijse-qfstpotjohvmbstjnqmfqsftfoudzqifst,qsftfouqbsujdjqmfdzqifsjoh,tjnqmfqbtudzqifs(uijse-qfstpotjohvmbstjnqmfqsftfoudzqifst,qsftfouqbsujdjqmfdzqifsjoh,tjnqmfqbtuboedzqifs(uijse-qfstpotjohvmbstjnqmfqsftfoudzqifst,qsftfouqbsujdjqmfdzqifsjoh,tjnqmfqbtuboeqbtudzqifs(uijse-qfstpotjohvmbstjnqmfqsftfoudzqifst,qsftfouqbsujdjqmfdzqifsjoh,tjnqmfqbtuboeqbtuqbsujdjqmfdzqifs(uijse-qfstpotjohvmbstjnqmfqsftfoudzqifst,qsftfouqbsujdjqmfdzqifsjoh,tjnqmfqbtuboeqbtuqbsujdjqmfdzqifsfe).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote