Пробовал несколько вариантов шифр/дешифр, везде по факту все работало, но валидатор ругается...
package com.javarush.task.task18.task1826;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/*
Шифровка
*/
public class Solution {
public static void main(String[] args) throws FileNotFoundException, IOException{
//String args1[] = {"-d","C:\\Users\\User\\Desktop\\wer.txt", "C:\\Users\\User\\Desktop\\qwe.txt"};
switch (args[0]){
case "-e": encryptFile(args[1], args[2]);
case "-d": decryptFile(args[1], args[2]);
}
}
private static void encryptFile(String inputFileName, String outputFileName) throws FileNotFoundException, IOException{
BufferedInputStream fis = new BufferedInputStream( new FileInputStream(inputFileName));
FileOutputStream fos = new FileOutputStream(outputFileName);
byte [] byteArray = new byte[fis.available()];
fis.read(byteArray);
byte[] key = "MyKey".getBytes();
byte[] res = new byte[byteArray.length];
for (int i = 0; i < byteArray.length; i++) {
res[i] = (byte) (byteArray[i] ^ key[i % key.length]);
}
fos.write(res);
fos.close();
fis.close();
}
private static void decryptFile(String inputFileName, String outputFileName) throws FileNotFoundException, IOException{
BufferedInputStream fis = new BufferedInputStream( new FileInputStream(inputFileName));
FileOutputStream fos = new FileOutputStream(outputFileName);
byte [] byteArray = new byte[fis.available()];
fis.read(byteArray);
byte[] key = "MyKey".getBytes();
byte[] res = new byte[byteArray.length];
for (int i = 0; i < byteArray.length; i++) {
res[i] = (byte) (byteArray[i] ^ key[i % key.length]);
}
fos.write(res);
fos.close();
fis.close();
}
}