Что не так с моим кодом?
package com.javarush.task.task18.task1826;
import java.io.*;
import java.util.Random;
/*
Шифровка
*/
public class Solution {
public static void main(String[] args) {
String stringKey = args[0];
String fileName = args[1];
String fileOutputName = args[2];
///////////////read from file/////////////
String fileContent = "";
StringBuilder contentBuilder = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null)
{
contentBuilder.append(sCurrentLine).append("\n");
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
fileContent = contentBuilder.toString();
//////////////////////////////////////////
//-------generate keys-------//
Random rClass = new Random();
int t = fileContent.length();
int [] keys = new int[t];
for(int i=0;i<t;i++){
keys[i] = rClass.nextInt();
}
//---------------------------//
//------final string---------//
String finalString;
if (stringKey.equalsIgnoreCase("-e")){
finalString = Encrypt(fileContent,keys);
} else if (stringKey.equalsIgnoreCase("-d")) {
finalString = Decrypt(fileContent,keys);
} else {
finalString = "";
}
//---------------------------//
/////////////////write to file///////////////
FileWriter fw;
BufferedWriter bw;
try {
fw = new FileWriter(fileOutputName);
bw = new BufferedWriter(fw);
bw.write(finalString);
fw.close();
bw.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
/////////////////////////////////////////////
}
public static String Encrypt(String fileContent,int[] keys){
//convert to bytes
byte[] bytes = fileContent.getBytes();
//get new bytes
byte[] NewBytes = new byte[fileContent.length()];
for (int i = 0; i < NewBytes.length; i++) {
NewBytes[i]=bytes[i+keys[i]];
}
String s = new String(NewBytes);
return s;
}
public static String Decrypt(String fileContent,int[] keys){
//convert to bytes
byte[] bytes = fileContent.getBytes();
//get new bytes
byte[] NewBytes = new byte[fileContent.length()];
for (int i = 0; i < NewBytes.length; i++) {
NewBytes[i]=bytes[i-keys[i]];
}
String s = new String(NewBytes);
return s;
}
}