长度为 N 的字母表中所有字母的排列
我最近开始了一个用 C 语言处理的个人项目,涉及暴力密码破解和密码破解。加密。我一直在尝试开发一个输出长度为 N 的字母表的所有可能组合的函数。例如,如果 N = 4,则必须输出 aaaa - zzzz 的所有可能性。从逻辑上讲,我不明白应该如何递归地处理这个问题。
char* alphabet[] = {"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"};
void passwords(int size){
char* password[size];
char* result;
//Determining static letter
for(int i = 0; i < size; i++){
for(int x = 0; x < size; x++){
password[x] = "a";
}
int index = i+1; //password index to modify
while(index < size){
for(int j = 0; j < 26; j++){
password[i] = alphabet[j];
printf("%s\n",password);
}
index++;
}
}
}
int main(int argc, char* argv[]){
passwords(3);
return 0;
}
目前,该程序仅修改字母表中的一个字符并产生以下输出:
aaa
baa
caa
daa
...//e-z aa
aaa
aba
aca
ada
...//a e-z a
aaa
aab
aac
aad
...//aa e_z
任何建议将非常感谢!
I recently began a personal project in C dealing with brute-force password cracking & encryption. I have been attempting to work on a function that outputs all possible combinations of the alphabet of length N. For example if N = 4, all possibilities from aaaa - zzzz would have to be outputted. Logically, I'm not understanding how I should approach this recursively.
char* alphabet[] = {"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"};
void passwords(int size){
char* password[size];
char* result;
//Determining static letter
for(int i = 0; i < size; i++){
for(int x = 0; x < size; x++){
password[x] = "a";
}
int index = i+1; //password index to modify
while(index < size){
for(int j = 0; j < 26; j++){
password[i] = alphabet[j];
printf("%s\n",password);
}
index++;
}
}
}
int main(int argc, char* argv[]){
passwords(3);
return 0;
}
Currently this program only modifies one character of the alphabet and produces an output of:
aaa
baa
caa
daa
...//e-z aa
aaa
aba
aca
ada
...//a e-z a
aaa
aab
aac
aad
...//aa e_z
Any suggestions would be great thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果使用递归不是强制要求,请尝试:
If the usage of recursion is not the mandatory requirement, would you please try: