gpt4 book ai didi

java - 初始化二维数组 - 密码表

转载 作者:行者123 更新时间:2023-12-04 02:31:14 25 4
gpt4 key购买 nike

我需要创建一个密码表,但我不知道该怎么做。这段代码:

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));
}

输出:

[[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],

一遍又一遍。 codekey 将在中给出,但现在我有“H”和“key”作为输入。表格需要看起来像这样,忽略蓝色的行和列:

enter image description here

图片中的 code 是 '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());
}
}

关于java - 初始化二维数组 - 密码表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64092772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com