import [Link].
*;
import [Link];
public class FileEncryptionDecryption {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("File Encryption/Decryption ");
[Link]("Choose one task (1 for encryption, 2 for decryption): ");
int choice = [Link]();
if (choice != 1 && choice != 2) {
[Link]("Invalid choice. Please enter 1 for encryption or 2
for decryption.");
return;
}
[Link]("Enter the input fileName: ");
String inputFileName = [Link]();
[Link]("Enter the output fileName: ");
String outputFileName = [Link]();
try {
File inputFile = new File(inputFileName);
File outputFile = new File(outputFileName);
if (![Link]()) {
[Link]("file not found");
return;
}
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
if (choice == 1) {
// Encryption
String line;
while ((line = [Link]()) != null) {
String encryptedLine = encrypt(line);
[Link](encryptedLine);
[Link]();
}
[Link]("the Encryption completed.");
} else if (choice == 2) {
// Decryption
String line;
while ((line = [Link]()) != null) {
String decryptedLine = decrypt(line);
[Link](decryptedLine);
[Link]();
}
[Link]("the Decryption completed.");
}
[Link]();
[Link]();
} catch (IOException e) {
[Link]("An error has been occurred: " + [Link]());
}
}
OUTPUT:
File Encryption/Decryption
Choose one task (1 for encryption, 2 for decryption): 1
Enter the input fileName: [Link]
Enter the output fileName: [Link]
the Encryption completed.