注意:请不要评论这个问题。对于那些认为我这样做是为了“欺骗”的人;你错了,因为我已经不在学校了。另外,如果我是,我自己实际上试图欺骗,我只会使用已经为此创建的服务,而不是重新创建该程序。我接受了这个项目,因为我认为这可能很有趣,没有别的。在您投票之前,请先consider the value of the question it's self,而不是它的推测性用法,因为SO的目的不是判断,而仅仅是提供公共信息。
我正在开发一个假定故意损坏文件的程序(特别是.doc,txt或pdf,但其他程序也会很好)
我最初尝试这样做:
public void corruptFile (String pathInName, String pathOutName) {
curroptMethod method = new curroptMethod();
ArrayList corruptHash = corrupt(getBytes(pathInName));
writeBytes(corruptHash, pathOutName);
new MimetypesFileTypeMap().getContentType(new File(pathInName));
// "/home/ephraim/Desktop/testfile"
}
public ArrayList getBytes(String filePath) {
ArrayList fileBytes = new ArrayList();
try {
FileInputStream myInputStream = new FileInputStream(new File(filePath));
do {
int currentByte = myInputStream.read();
if(currentByte == -1) {
System.out.println("broke loop");
break;
}
fileBytes.add(currentByte);
} while (true);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(fileBytes);
return fileBytes;
}
public void writeBytes(ArrayList hash, String pathName) {
try {
OutputStream myOutputStream = new FileOutputStream(new File(pathName));
for (int currentHash : hash) {
myOutputStream.write(currentHash);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println(hash);
}
public ArrayList corrupt(ArrayList hash) {
ArrayList corruptHash = new ArrayList();
ArrayList keywordCodeArray = new ArrayList();
Integer keywordIndex = 0;
String keyword = "corruptthisfile";
for (int i = 0; i < keyword.length(); i++) {
keywordCodeArray.add(keyword.codePointAt(i));
}
for (Integer currentByte : hash) {
//Integer currentByteProduct = (keywordCodeArray.get(keywordIndex) + currentByte) / 2;
Integer currentByteProduct = currentByte - keywordCodeArray.get(keywordIndex);
if (currentByteProduct < 0) currentByteProduct += 255;
corruptHash.add(currentByteProduct);
if (keywordIndex == (keyword.length() - 1)) {
keywordIndex = 0;
} else keywordIndex++;
}
//System.out.println(corruptHash);
return corruptHash;
}但问题是该文件仍然可以打开。当你打开文件时,所有的单词都被改变了(它们可能没有任何意义,甚至可能不是字母,但它仍然可以打开)
所以这里是我的实际问题:
有没有办法让一个文件如此腐败,以至于电脑根本不知道如何打开它(例如,当你打开它时,计算机会沿着“这个文件不被识别,并且不能被打开“)?