有一种编码文件的方法
public static void cipher(File input, int[] key, File output) throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(10);
FileInputStream fin = new FileInputStream(input);
FileChannel fcin = fin.getChannel();
FileOutputStream fout = new FileOutputStream( output );
FileChannel fcout = fout.getChannel();
ByteBuffer temp;
while (true){
buffer.clear();
int r = fcin.read(buffer);
if(r == -1){
break;
}
//cb = StandardCharsets.UTF_8.decode(cipherBuffer(buffer,key));
//System.out.println(cb.toString());
temp = cipherBuffer(buffer,key);
for (int i = 0; i < 10; i++){
System.out.print((char)temp.get(i));
}
temp.flip();
fcout.write(temp);
}
}
cipherBuffer()
方法根据给定的密钥更改初始缓冲区。
试图使用注释代码,但它没有帮助。目前它甚至没有写入output
public static ByteBuffer cipherBuffer(ByteBuffer initialBuffer, int[] key){
ByteBuffer result = ByteBuffer.allocate(10);
for (int i = 0; i < 10; i++){
result.put(i, initialBuffer.get(key[i]));
//System.out.println(result.get(i));
}
return result;
}
这就是现阶段输出的样子
ᄚᄎᄋᄏᄚᄇタ ᄒᄈムᄒᄡ ᄉテᄒᄏ