我目前正在研究python项目,以模仿或重新创建通过暴力破解密码作为计算机科学项目的方法。我收到一个内存错误,因为它试图建立在较旧的失败尝试之上,但是我无法找出一种不用生成器就可以在较旧的失败之上运行代码的方法。
我尝试重新排列代码行,重新格式化并完全删除列表。
def product(*args, Answer, repeat=1):
i = 0
pools = [tuple(pool) for pool in args] * repeat
result = [[]]
for pool in pools:
for x in result:
for y in pool:
StrX = ''
for f in range(len(x)):
StrX = StrX + x[f]
Code = StrX+y
i = i + 1
if Code == Answer :
print("It took the Machine", i, "tries to guess your password")
print("Your password was", Code)
break
result = [x+[y] for x in result for y in pool]
我希望它产生的输出表明尝试次数,但是失败并给我一个MemoryError