分解你的问题。
- 生成所有一个字符串 A - Z
- 生成所有 2 个字符串 AA - ZZ
- 生成所有 3 个字符串 AAA - ZZZ
- 等等
现在考虑将例如 AAA - ZZZ 视为以 26 为基数打印所有可能的 3 位数字的问题(或者无论您的字符集中有多少字符)
开膛手约翰开始使用不同的技术,内置字典:
密码
密码
passw0rd
Passw0rd
等
ETA:这是两个字符版本 AA - ZZ 的一些示例代码。我的 C 非常生锈,所以这个片段是 Java:
// Character set
String charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int cSetSize = charset.length();
// Two character strings AA - ZZ
int numChars = 2;
int limit = cSetSize * cSetSize;
char[] result = new char[numChars];
// Build strings
for (int i = 0; i < limit; ++i) {
// Convert i to base cSetSize
int current = i;
for (int j = numChars - 1; j >= 0; --j) {
result[j] = charset.charAt(current % cSetSize);
current /= cSetSize;
}
// Do something with string
System.out.println(new String(result));
}