gpt4 book ai didi

python-3.x - Itertool的Python内存错误

转载 作者:行者123 更新时间:2023-12-03 17:38:23 26 4
gpt4 key购买 nike

我有一个小的Bruteforce计划要上学。
我已经编写了一个程序,但是当我运行代码时,出现“内存错误” ...
这是我的IDE发出的消息:


密码= [''.join(word)for itertools.product中的单词(字母,重复= CharLength)]
MemoryError


我想大多数错误是由于我如何使用循环号?
作为菜鸟,我永远不会遇到这种类型的错误...我给了您1条更多信息,我正在Windows上运行我的代码

如何优化我的代码以及如何修复?
这是我的代码:

import hashlib
import itertools


#possible characters in user password
Alphabet = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_.;#@")
#minimum password value
CharLength = 6

#getting passwords and username from shadow file
with open("shadow_test", "r") as ins:
array = []
users = []
passwd = []
#getting everyline from shadow file into an array
for line in ins:
array.append(line)
#saving only username and passwords
for pw in array:
str(pw)
r= pw.split(":")
users.append(r[0])
passwd.append(r[1])

list = []
#removing passowrd with * or !
for mdp in passwd:
if mdp != '*' and mdp != '!':
str(mdp)
list.append(mdp)
# trying to Bruteforce
for _ in range(12):
passwords = [''.join(word) for word in itertools.product(Alphabet, repeat=CharLength)]

print(*passwords)
for pswd in passwords:
hash_object = hashlib.md5(str.encode(pswd)).hexdigest()
# hash_object.update(*passwords.encode('utf-8'))
generatedpassword = '$1$' + hash_object

for compare in list:
for user in users:
#print('on cherche le Mot de passe : ' + compare +' pour ' +user)
#print('mot de passe MD5 généré : ' +generatedpassword)
#print('mot de passe clair généré : ' +pswd)


if generatedpassword == list:
print('Le Mot de passe pour' + user + ' est : ' + compare)

最佳答案

passwords = [''.join(word) for word in itertools.product(Alphabet, repeat=CharLength)]


在这里,您创建的列表长度超过50 ** 6。当然,您会遇到内存错误。改用生成器:

passwords = (''.join(word) for word in itertools.product(Alphabet, repeat=CharLength))

关于python-3.x - Itertool的Python内存错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54279702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com