所以我需要破解一个哈希来解决一个难题,我已经编辑了一个迭代所有可能组合的Python程序,但是Python程序太慢了,因为哈希每天都在变化,我知道#&# 39; sa长度:8
python程序的工作原理如下:
charset = "abcdefghijklmnopqrstuvwxyz012345679"
NUMBER_OF_CHARACTERS = len(charset)
sequence = list("a a a a a a a a".split(" "))
while(True):
current = "".join(sequence)
sequence = next(sequence)
#check if hash of sequence matches target hash
功能:' next'看起来像这样:
if len(string) <= 0:
string.append(indexToCharacter(0))
else:
string[0] = indexToCharacter((characterToIndex(string[0]) + 1) % NUMBER_OF_CHARACTERS)
if characterToIndex(string[0]) is 0:
return list(string[0]) + next(string[1:])
return string
indexToCharacter只返回索引(索引)
的字符串字符集中的字符
characterToIndex返回字符串索引
所以,characterToIndex(&#34; a&#34;)将返回0并且indexToCharacter(0)将返回&#34; a&#34;
现在我需要的是,将这个Python程序转换为C ++程序,因为C ++更快,我有indexToCharacter函数,characterToIndex函数,但我似乎无法使下一个函数工作。
我在C ++的下一个函数中得到了这个
string next(string sequence)
{
sequence[0] = indexToCharacter(characterToIndex(sequence[0])+1);
if (characterToIndex(sequence[0]) == 0)
{
//Something
}
}
string sequence = "aaaaaaaa";
next(sequence);
indexToCharacter的代码和characterToIndex:
int characterToIndex(char character)
{
return charset.find(character);
}
char indexToCharacter(unsigned index)
{
return charset[index];
}
答案 0 :(得分:1)
在这种特殊情况下,我不会一直使用std :: string对象。你有一个固定的长度,对吗?你可以通过这种方式非常有效地完成它(在C ++和C中都可以工作...... - 只需根据自己的需要调整缓冲区长度和字符列表):
char characters[] = { 'a', 'b', 'c' };
char buffer[3];
char* positions[sizeof(buffer)];
for(unsigned int i = 0; i < sizeof(buffer); ++i)
{
buffer[i] = *characters;
positions[i] = characters;
}
unsigned int i;
do
{
printf("%.*s\n", (int)sizeof(buffer), buffer);
for(i = 0; i < sizeof(buffer); ++i)
{
++positions[i];
if(positions[i] < characters + sizeof(characters))
{
buffer[i] = *positions[i];
break;
}
positions[i] = characters;
}
}
while(i < sizeof(buffer));
我刚打印出价值观,你可以做任何你需要做的事情......