我的代码中的哪些内容可以被识别为病毒?

时间:2014-12-19 10:34:27

标签: java

当我完成家庭任务时,我收到错误“无法找到或加载主要课程”。 我花了近20分钟才完全消解。原因是“卡巴斯基反病毒”,它阻止了我的MyClass.class 这是代码,谁知道,卡巴斯基可以识别出什么病毒?

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;

public class CryptoUtil extends JFrame{
    private String keyWord;
    private JFileChooser inputFileChooser = new JFileChooser();
    private JButton openFileChooser = new JButton("Выбрать файл");
    private JTextField inputKeyWord = new JTextField();
    private JButton operate = new JButton("Выполнить");
    private File inputFile;
    private File encode;
    private File decode;
    private String inputData;


public CryptoUtil(){
    initFrame();
}

public void initFrame(){
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setTitle("Шифратор/дешифратор XOR");
    this.setLayout(new GridLayout(3, 1));
    this.setSize(300, 100);
    operate.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                operate();
                Desktop.getDesktop().open(new File(encode.getParent()));
            } catch (IOException e1) {
                e1.printStackTrace();
            }

        }
    });
    openFileChooser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            inputFileChooser.showOpenDialog(CryptoUtil.this);
        }
    });
    this.add(openFileChooser);
    this.add(inputKeyWord);
    this.add(operate);
}

public void operate() throws IOException {
    keyWord = inputKeyWord.getText();
    inputFile = inputFileChooser.getSelectedFile();
    encode = new File(inputFile.getParent() + "//encode.txt");
    decode = new File(inputFile.getParent() + "//decode.txt");
    BufferedReader br = new BufferedReader(new FileReader(inputFile));
    StringBuilder sb = new StringBuilder();
    String line = br.readLine();
    while (line != null) {
        sb.append(line);
        sb.append(System.lineSeparator());
        line = br.readLine();
    }
    inputData = sb.toString();
    br.close();
    PrintWriter writerEn = new PrintWriter(encode, "UTF-8");
    writerEn.print(encrypt(inputData, keyWord));
    writerEn.close();
    PrintWriter writerDe = new PrintWriter(decode, "UTF-8");
    writerDe.print(decrypt(encrypt(inputData, keyWord), keyWord));
    writerDe.close();
}


public byte[] encrypt(String text, String keyWord){
    byte[] arr = text.getBytes();
    byte[] keyArr = keyWord.getBytes();
    byte[] result = new byte[arr.length];
    for(int i = 0; i < arr.length; i++){
        result[i] = (byte) (arr[i] ^ keyArr[i % keyArr.length]);
    }
    return result;
}

public String decrypt(byte[] text, String keyWord){
    byte[] result  = new byte[text.length];
    byte[] keyArr = keyWord.getBytes();
    for(int i = 0; i < text.length;i++){
        result[i] = (byte) (text[i] ^ keyArr[i% keyArr.length]);
    }
    return new String(result);
}

public static void main(String[] args) {
    new CryptoUtil().setVisible(true);
}

}

1 个答案:

答案 0 :(得分:0)

你可以在kaspersky杀毒软件中将你的文件添加为信任,同样也发生在我身上,一定不会是病毒。