package com.codegym.task.task18.task1826;

/*
Encryption

*/

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Solution {
    public static void main(String[] args) throws IOException {

        FileInputStream fileInputStream = new FileInputStream(args[1]);
        FileOutputStream fileOutputStream = new FileOutputStream(args[2]);

        //here we read the byte value of a character in the data of the fileName file
        //then we do a basic encryption by adding 3 to the bytevalue so it transforms it into
        //another character
        if (args[0].equals("-e")) {
            while (fileInputStream.available() > 0) {
                int dataReadAndEncoded = fileInputStream.read() + 3;
                fileOutputStream.write(dataReadAndEncoded);
            }
        }

        //here we do the opposite: we read a byte value and then we subtract 3 to get to the
        //"real" value of the character and then we write it to the fileOutputName file.
        if (args[0].equals("-d")) {
            while (fileInputStream.available() > 0) {
                int dataReadAndDecoded = fileInputStream.read() - 3;
                fileOutputStream.write(dataReadAndDecoded);
            }
        }

        fileInputStream.close();
        fileOutputStream.close();

        //Hope it helps!

    }
}