我试图解决一个谜题,即对此代码进行反向工程,以获取可能的密码列表,并且应该有一个突出的passwords,并且应该工作
function checkPass(password) {
var total = 0;
var charlist = "abcdefghijklmnopqrstuvwxyz";
for (var i = 0; i < password.length; i++) {
var countone = password.charAt(i);
var counttwo = (charlist.indexOf(countone));
counttwo++;
total *= 17;
total += counttwo;
}
if (total == 248410397744610) {
//success//
} else {...
我在python中写了一些我认为应该工作的东西,我反向设计它添加和增加的顺序,并让它尝试每个字符以查看它是否正确地分成偶数。
from random import shuffle
def shuffle_string(word):
word = list(word)
shuffle(word)
return ''.join(word)
charlist = "abcdefghijklmnopqrstuvwxyz"
total = 248410397744610
temp = total
password = ''
runtime = 20
def runlist():
global charlist
global total
global temp
global password
global runtime
for i in range(25):
if (temp - (i+1)) % 17 == 0:
password += charlist[i]
temp -= i+1
temp = temp /17
if temp == 0:
print password
password = ''
temp = total
runtime += 1
charlist = shuffle_string(charlist)
if runtime < 21:
runlist()
else:
runlist()
但是当我尝试运行它时我只能
deisx
Process finished with exit code 0
我想知道为什么我的功能没有正确递归,因为它看起来应该是我看到的。尝试自己运行,看看会发生什么。
这个谜题应该有多种解决方案(我认为?),我正在计划让它能够重复,直到它获得所有解决方案,但我很少会忘记为什么它只是贯穿每一个字母一次然后就死了。
修改: 修改后的代码实际递归,但现在我没有输出,仍然以退出代码0完成。
编辑2: 再次修改代码以修复错误
答案 0 :(得分:0)
您的代码既不重复也不重复,因为:
runlist
功能仅调用一次runlist
函数不适合递归模式,即:
答案 1 :(得分:0)
害怕我不太了解python,但我可以帮助你解决这个问题。
编码过程重复以下内容:
所以在任何时候,总数是17的倍数加上最后一个字母的值。因此,递归求解器中的每一步都必须删除最后一个字母,然后将结果除以17。
但是,因为乘数为17且字母表中有26个字符,所以剩余的一些值可能由多个字母产生 - 这是许多密码可能产生相同解决方案的地方。
例如:
因此,如果当前余数为1,则编码后的字母可以是&#34; a&#34;或&#34; r&#34;。我认为在您的解决方案中,您只会查找第一个案例,而忽略第二个案例。
在伪代码中,我解决这个问题的函数看起来像是:
function decodePassword(total, password)
if total == 0
print password
return
end if
var rem = total / 17 # integer division - truncate
var char1 = total % 17 # potential first character
var char2 = char1 + 17 # potential second character
# char1 values 1-16 map to letters a-p
if char1 >= 1
decodePassword(rem, charlist.charAt(char1 - 1) + password)
end if
# char2 values 17-26 map to letters q-z
if rem > 0 && char2 <= 26
decodePassword(rem - 1, charlist.charAt(char2 - 1) + password)
end if
end function
如果它有帮助,你要找的答案是12个字符长,可能在这个论坛中不可打印!
HTH