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")
结果是,您迅速看到了为什么通过蛮力破裂密码是良好的密码的问题。