逻辑来选择从笛卡尔集一组特定的 [英] Logic to select a specific set from Cartesian set
问题描述
我正在做一个密码暴力破解工具,作为一个学习锻炼,我希望它是可恢复的。
所以,我要的是要能够说,这是一组可能的字符,如果我计算笛卡尔集此每个可能的组合的设置长度为n,什么是该组点x
不过,我想这样做,不计算整个集合。我已经看到了同样的逻辑在一个地方在线,但我无法推广为适应。
任何帮助将是非常美妙的,谢谢!我很精通C#有没有什么帮助。
编辑:这是我刚才提到的问题:的如何选择笛卡尔积特定项目不计算其他所有项
编辑:这里是我的意思的例子:
字符集= [ ABCD]
长度为n = 4
置换:
[AAAA]
[AAAB]
[AAAC]
〔AAAD]
[AABA]
....
[DDDD]
所以,如果我在4搜索的集合,我会得到[AAAD。但是,如果我在寻找7000元,那么它需要较长的时间才能到这一点。
这实现了回答您链接的问题:
静态字符串获取(串字符,整数N,int i)以
{
串RET =;
INT尺寸= 1;
为(INT J = 0; J< N; J ++){$ B $ B RET =字符[(I /尺寸)%chars.Length] + RET;
尺寸* = chars.Length;
}
返回RET;
}
例如:
字符串的字符=ABCD;
INT N = 3;
的for(int i = 0; I< Math.Pow(chars.Length,N);我++)
Console.WriteLine(我+\t+获取(字符,N,I));
0 AAA
1分配AAB
2 AAC
3 AAD
...
61 DDB
62 DDC
63 DDD
块引用>I'm making a password brute forcing tool as a learning exercise, and I want it to be resumable.
So, what I want is to be able to say, this is the set of possible characters, if I computed the Cartesian set of every possible combination of this set up to length n, what is the set at point x?
However, I want to do this without computing the entire set. I've seen similar logic in one place online but I was unable to generalise this to fit.
Any help would be fantastic, thanks! I'm fluent in C# if that helps.
Edit: Here's the question I mentioned earlier: How to select specific item from cartesian product without calculating every other item
Edit: here's an example of what I mean:
Char set = [abcd] Length n = 4 Permutations: [aaaa] [aaab] [aaac] [aaad] [aaba] .... [dddd]
So if I'm searching for the set at 4, I'd get [aaad]. But if I'm searching for element 7000, then it takes a long time to get to that point.
解决方案This implements the answer to the question you link:
static string Get(string chars, int n, int i) { string ret = ""; int sizes = 1; for (int j = 0; j < n; j++) { ret = chars[(i / sizes) % chars.Length] + ret; sizes *= chars.Length; } return ret; }
Example:
string chars = "abcd"; int n = 3; for (int i = 0; i < Math.Pow(chars.Length, n); i++) Console.WriteLine(i + "\t" + Get(chars, n, i));
0 aaa 1 aab 2 aac 3 aad ... 61 ddb 62 ddc 63 ddd
这篇关于逻辑来选择从笛卡尔集一组特定的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!