This totally works, accepts that the "-e" encrypts the file, but despite the "-d" doing exactly the opposite, apparently that doesn't pass.....
port java.util.List;
public class Solution {
static List<Integer> bytes = new ArrayList<>();
public static void main(String[] args) {
try {
if (args[0].equals("-e")) {
Encrypt(args[1], args[2]);
}
if (args[0].equals("-d")) {
Decrypt(args[1], args[2]);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void Encrypt(String InputFilename, String OutputFilename) throws IOException {
BufferedInputStream readFile = new BufferedInputStream(new FileInputStream(InputFilename));
while (readFile.available() > 0) {
bytes.add(readFile.read());
}
readFile.close();
for (int i = 0; i < bytes.size(); i++) {
Integer toEncrypt = bytes.get(i);
Integer Encrypted = toEncrypt + 1;
bytes.set(i, Encrypted);
}
BufferedOutputStream writeFile = new BufferedOutputStream(new FileOutputStream(OutputFilename));
for (Integer x : bytes) {
writeFile.write(x);
}
writeFile.close();
}
public static void Decrypt(String InputFilename, String OutputFilename) throws IOException {
BufferedInputStream readFile = new BufferedInputStream(new FileInputStream(InputFilename));
while (readFile.available() > 0) {
bytes.add(readFile.read());
}
readFile.close();
for (int i = 0; i < bytes.size(); i++) {
Integer toEncrypt = bytes.get(i);
Integer Encrypted = toEncrypt - 1;
bytes.set(i, Encrypted);
}
BufferedOutputStream writeFile = new BufferedOutputStream(new FileOutputStream(OutputFilename));
for (Integer x : bytes) {
writeFile.write(x);
}
writeFile.close();
}
}
package com.codegym.task.task18.task1826;
/*
Encryption
*/
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class Solution {
static List<Integer> bytes = new ArrayList<>();
public static void main(String[] args) {
try {
if (args[0].equals("-e")) {
Encrypt(args[1], args[2]);
}
if (args[0].equals("-d")) {
Decrypt(args[1], args[2]);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void Encrypt(String InputFilename, String OutputFilename) throws IOException {
BufferedInputStream readFile = new BufferedInputStream(new FileInputStream(InputFilename));
while (readFile.available() > 0) {
bytes.add(readFile.read());
}
readFile.close();
for (int i = 0; i < bytes.size(); i++) {
Integer toChange = bytes.get(i);
Integer changed = toChange + 1;
bytes.set(i, changed);
}
BufferedOutputStream writeFile = new BufferedOutputStream(new FileOutputStream(OutputFilename));
for (Integer x : bytes) {
writeFile.write(x);
}
writeFile.close();
}
public static void Decrypt(String InputFilename, String OutputFilename) throws IOException {
BufferedInputStream readFile = new BufferedInputStream(new FileInputStream(InputFilename));
while (readFile.available() > 0) {
bytes.add(readFile.read());
}
readFile.close();
for (int i = 0; i < bytes.size(); i++) {
Integer toChange = bytes.get(i);
Integer changed = toChange - 1;
bytes.set(i, changed);
}
BufferedOutputStream writeFile = new BufferedOutputStream(new FileOutputStream(OutputFilename));
for (Integer x : bytes) {
writeFile.write(x);
}
writeFile.close();
}
}