每一个字符组合起来产生一定字长 [英] Generating every character combination up to a certain word length
问题描述
我做我在几个星期的时间计算机和信息安全过程安全演示,并在此演示文稿我将展示的优点和不同的攻击(字典,彩虹和暴力破解)利弊。我做了字典和彩虹精的攻击,但我需要动态生成的暴力破解攻击。我需要找到一个算法,可以让我周期,虽然字母,符号和数字达到一定的字符长度的每个组合。
I am doing a security presentation for my Computer and Information Security course in a few weeks time, and in this presentation I will be demonstrating the pros and cons of different attacks (dictionary, rainbow and bruteforce). I am do the dictionary and rainbow attacks fine but I need to generate the bruteforce attack on the fly. I need to find an algorithm that will let me cycle though every combination of letter, symbol and number up to a certain character length.
所以,作为一个例子,一个字符12的长度,第一个和最后几代人将是:
So as an example, for a character length of 12, the first and last few generations will be:
a
ab
abc
abcd
...
...
zzzzzzzzzzzx
zzzzzzzzzzzy
zzzzzzzzzzzz
但是,它也将采用数字和符号,所以它是很困难,我解释...但我认为你的想法。从ASCII表只使用符号的罚款。
But it will also use numbers and symbols, so it's quite hard for me to explain... but I think you get the idea. Using only symbols from the ASCII table is fine.
我可以使用ASCII函数与反做这样的图片,但我只是不能工作了在我的脑子里。如果任何人都可以提供一些源代码(我可能会使用C#),甚至一些伪代码,我可以计划从一个函数将会很大。
I can kind of picture using an ASCII function to do this with a counter, but I just can't work it out in my head. If anyone could provide some source code (I'll probably be using C#) or even some pseudo code that I can program a function from that'd be great.
感谢你提前。 :)
推荐答案
一个递归函数将让你通过ValidChars的所有组合运行:
A recursive function will let you run through all combinations of ValidChars:
int maxlength = 12;
string ValidChars;
private void Dive(string prefix, int level)
{
level += 1;
foreach (char c in ValidChars)
{
Console.WriteLine(prefix + c);
if (level < maxlength)
{
Dive(prefix + c, level);
}
}
}
分配一套有效的字符到ValidChars,要最大长度字符串的最大长度,然后调用潜水(,0);和远离你去。
Assign the set of valid characters to ValidChars, the maximum length of string you want to maxlength, then call Dive("", 0); and away you go.
这篇关于每一个字符组合起来产生一定字长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!