【发布时间】:2023-03-07 06:49:02
【问题描述】:
我需要编写一个替换密码加密器。但是,我不知道如何从密码创建一个字母以匹配普通字母以生成我的加密消息
它应该给出类似的东西
String passphrase = "mobile";
byte[] expected = {'m', 'o', 'b', 'i', 'l', 'e', 'a', 'c', 'd', 'f' ...};
如何编写一个返回预期字母的函数?
【问题讨论】:
我需要编写一个替换密码加密器。但是,我不知道如何从密码创建一个字母以匹配普通字母以生成我的加密消息
它应该给出类似的东西
String passphrase = "mobile";
byte[] expected = {'m', 'o', 'b', 'i', 'l', 'e', 'a', 'c', 'd', 'f' ...};
如何编写一个返回预期字母的函数?
【问题讨论】:
顺便说一句,您确实应该使用char 数组。如果您真的不想要一个 char 数组,只需将所有内容转换为字节即可。
static char[] generateExpected(String passphrase) {
char[] expected = new char[passphrase.length() + 26];
passphrase.getChars(0, passphrase.length(), expected, 0);
for (int i = 0; i < 26; i++) {
expected[i + passphrase.length()] = (char) ('a' + i);
}
return expected;
}
【讨论】: