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!
}
}
Andrei
Level 41
Here is a simple version of how you can achieve a basic Caesar Cypher - you can study it to understand the algorithm but I recommend to write the program from your memory!
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Mike McKenna
28 January 2021, 21:27
Hi Andrei,
Thanks for the code !
Mike
+1
Andrei
29 January 2021, 07:44
Hi Mike, you're welcome! Glad it was of use.
0