crypt/decrypt
shitunknown
java
4 years ago
1.3 kB
6
Indexable
public class Solution { public static void main(String[] args) throws IOException { switch (args[0]) { case "-e" -> crypto(args[1], args[2]); case "-d" -> unCrypto(args[1], args[2]); } } public static void crypto(String firstFile,String secondFile) throws IOException { FileOutputStream fileOutputStreamE = new FileOutputStream(secondFile); for (Integer integer : getData(firstFile)) { fileOutputStreamE.write(integer+1); } fileOutputStreamE.close(); } public static void unCrypto(String firstFile,String secondFile) throws IOException { FileOutputStream fileOutputStreamD = new FileOutputStream(secondFile); for (Integer integer : getData(firstFile )) { fileOutputStreamD.write(integer-1); } fileOutputStreamD.close(); } public synchronized static ArrayList<Integer> getData(String firstFile) throws IOException { FileInputStream fileInputStream = new FileInputStream(firstFile); ArrayList<Integer> list = new ArrayList<Integer>(); while (fileInputStream.available()>0){ list.add(fileInputStream.read()); } fileInputStream.close(); return list; } }
Editor is loading...