Java 初始化二维数组密码表
我需要创建一个密码表,我一直在做什么。此代码:Java 初始化二维数组密码表,java,arrays,encryption,multidimensional-array,Java,Arrays,Encryption,Multidimensional Array,我需要创建一个密码表,我一直在做什么。此代码: public class Prog3Cipher { // INSTANCE VARIABLES static char [ ] keyList; // VARIABLE DESCRIPTION COMMENT static char [ ][ ] cipherTable; // VARIABLE DESCRIPTION COMMENT String alpha = "ABCDEFGHIJKLMNOPQRS
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));
}
一遍又一遍。code
和key
将在中给出,但现在我有'H'和'key'作为输入。该表需要如下所示,忽略蓝色的行和列:
图片中的
code
是“H”,因此[0][0]元素是“H”,字母表在相邻的行和列中继续。我将使用完成的表格对消息进行编码和解码,但现在我只需要表格正确。根据您共享的图像,您可以说,对于密文表中的每个单元格,字符应该是行索引+列索引+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());
}
}
int offset='H'-'A';
cipherTable=新字符[26][26];
for(int x=0;x
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());
}
}