我對加密非常好奇,於是我出去給自己做了一些小小的任務,加密一條消息(在我的.txt
文件中)。我沒有得到我想要的輸出,我只得到第一列。爲什麼只打印第一列?爲什麼我的數組不打印剩下的列?
這是我的java
文件:
import java.io.*;
public class EncryptDecrypt {
public static void encrypt() throws IOException {
BufferedReader in = new BufferedReader(new FileReader("cryptographyTextFile.txt"));
String line = in.readLine();
char[][] table = new char[5][5];
// fill array
for(int i = 0; i < table.length; i++) {
for(int j = 0; j < table.length; j++) {
table[i][j] = line.charAt(j);
}
}
// print array
for(int i = 0; i < table.length; i++) {
for(int j = 0; j < table.length; j++) {
System.out.println(table[i][j]);
}
System.out.println();
}
}
public static void main(String[] args) throws IOException {
encrypt();
}
}
我.txt
文件包含:
E5NOWISTHEWINTEROFOURDISCONTENT*
我output
是:
E
5
N
O
W
我希望我的output
是:
E I T W O O D
5 S H I F U I
N E N R S
O T C
W E O
R N
T
E
N
T
您可以隨時選擇任何東西。你必須編寫一個算法來加密和解密,然後在你的邏輯中實現加密或解密文本。某種分隔符,用於指定該文本將在第一列中出現,下一列中將出現下一文本。 如果你想了解更多關於這個,你可以參考http://docs.oracle.com/javase/7/docs/technotes/guides/security/crypto/CryptoSpec.html – Maverick
@Leozeo我不需要任何太花哨目前。一些簡單的東西,會逐列閱讀,並像我在原始文章中提到的那樣打印出來。 – yabva89