我的问题是,我一直在Python中获得记忆限制。我有三组代码生成一组字符的组合。我已经在模拟器上运行它,如果它试图生成长四个字符的组合,则可以以大约1/8的方式杀死自己。我用后斜线替换了后斜线角色。我的Python已更新为64位,但对于代码仍有一些内存错误。我有三个代码。顺便说一句,我更改了计算机上的设置,以使用32000到40000字节(我认为是字节)的内存。我还应该使用任务管理器优先考虑python吗? 所有的帮助非常感谢!

问题描述 投票:0回答:0

characters = ["~","!","@","#","$","%","^","&","*","(",")","_","+","`","1","2","3","4","5","6","7","8","9","0","-","=","Q","W","E","R","T","Y","U","I","O","P","{","}","|","q","w","e","r","t","y","u","i","o","p","[","]",'"BackslashCharacter"',"A","S","D","F","G","H","J","K","L",":",'"',"a","s","d","f","g","h","j","k",";","'","Z","X","C","V","B","N","M","<",">","?","z","x","c","v","b","n","m",",",".","/"," "] import itertools combinations = list(itertools.product(characters,repeat=3)) testfileofcombinationsname = "testfile.txt" size_in_bytes=(1024*1024) filename = "combinationsfile" import os def testtxtcombinationsfile(testfileofcombinationsname, size_in_bytes): with open({testfileofcombinationsname}, 'wb') as combinationsfile: {filename}.seek(size_in_bytes - 1) {filename}.write(b'\0') with open(testfileofcombinationsname, 'a') as combinationsfile: for row in combinations: line = " ".join(row) combinationsfile.write(line + '\n') print('A "said" table has been appended and written to testfile.txt!')

这是我的第三个代码:它还生成一个TXT文件并在其中打印组合。尽管我运行的模拟器说,考虑到寻求部分的少量数量,它的数量超过4KB。你知道为什么会发生这种情况吗?一旦,它生成了一个以红色突出显示的时期填充的文件。知道为什么会发生这种情况吗?您知道为什么当搜索号码如此之小时会生成如此大的文件吗?您知道一种正确使用寻求部分的方法,以创建一个尺寸8KB的TXT文件吗?有什么我能做的,可以使更多的记忆分配给它更好?

characters = ["~","!","@","#","$","%","^","&","*","(",")","_","+","`","1","2","3","4","5","6","7","8","9","0","-","=","Q","W","E","R","T","Y","U","I","O","P","{","}","|","q","w","e","r","t","y","u","i","o","p","[","]",'"BackslashCharacter"',"A","S","D","F","G","H","J","K","L",":",'"',"a","s","d","f","g","h","j","k",";","'","Z","X","C","V","B","N","M","<",">","?","z","x","c","v","b","n","m",",",".","/"," "] import itertools combinations = list(itertools.product(characters,repeat=3)) testfileofcombinationsname = "testfile.txt" combinationsfile = open("testfile.txt", "wb") combinationsfile.seek(4) combinationsfile.write(b"\0") with open(testfileofcombinationsname, 'a') as combinationsfile: for row in combinations: line = " ".join(row) combinationsfile.write(line + '\n')

	

仅标点符号,ASCII字符和数字的组合约为100(少一些,但100使数学更容易)。因此,长度4的密码导致1000万行文件,其中包含4个字符字符串或少于400meg的线。您的最终尝试是为了生成这样的文件。此代码使用3个密码长度。增加您自己的危险。

import string
import itertools

## ---------------------
## Waring about resulting file sizes:
##  1 == 1k
##  2 == 26k
##  3 == 3.2m
##  4 == 300m?
##  5 == 30g?
## ---------------------
password_length = 3
## ---------------------

possible_characters = string.ascii_letters + string.digits + string.punctuation
with open("passwords.txt", "w") as file_out:
    for attempt in itertools.product(possible_characters, repeat=password_length):
        file_out.write("".join(attempt) + "\n")

结果是,您迅速看到了为什么通过蛮力破裂密码是良好的密码的问题。


python memory-management out-of-memory
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.