Ale*_*lex 3 java arrays encryption multidimensional-array
我需要创建一个密码表,但我不知道该怎么做。这段代码:
public class Prog3Cipher {
// INSTANCE VARIABLES
static char [ ] keyList; // VARIABLE DESCRIPTION COMMENT
static char [ ][ ] cipherTable; // VARIABLE DESCRIPTION COMMENT
String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public Prog3Cipher( char code, String key ) {
String[] keyList = new String []{"key"};
cipherTable = new char[26][26];
cipherTable[0][0] = 'H';
for(int x = 0; x < cipherTable.length; x++){
for(int y = 0; y < cipherTable.length; y++){
cipherTable[x][y] = alpha.charAt(y);
}
}
System.out.println(Arrays.deepToString(cipherTable));
}
Run Code Online (Sandbox Code Playgroud)
输出:
[[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z], [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z], [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z],
Run Code Online (Sandbox Code Playgroud)
一遍又一遍。在code和key会中给出,但现在我有“H”和“关键”作为输入。表格需要看起来像这样,忽略蓝色的行和列:
的code在PIC是“H”,所以[0] [0]元素是“H”和字母表继续相邻的行和列英寸 我将使用完整的表格来编码和解码消息,但现在我只需要表格是正确的。
根据您共享的图像,您可以说对于 中的每个单元格cipherTable,字符应该是位于行索引位置的字符 + 列索引 + 7(看似任意幻数),以字母表,当然。如果我们表示这是 Java:
int offset = 'H' - 'A';
cipherTable = new char[26][26];
for (int x = 0; x < cipherTable.length; x++) {
for(int y = 0; y < cipherTable[0].length; y++) {
cipherTable[x][y] = alpha.charAt((x + y + offset) % alpha.size());
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
51 次 |
| 最近记录: |