-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpermuteri.py
64 lines (49 loc) · 2.85 KB
/
permuteri.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Take MyWordList and crack on with it
def permuteri():
import itertools as it
import time
import math
import shutil
## ## ## STEP 1: Get Inputs, includes a 3 second timeout, and using default name if enter is pressed without typing ## ## ## -----------------------------------------------
inputFileName = "MyWordList.txt"
print (" \n ", " opening ", inputFileName, "\n")
lineNos=0 # count how many lines there are to process
with open(inputFileName, 'r') as f:
for line in f:
lineNos += 1
print("> Total number of items to scramble is ----> ", (lineNos), "\n", "\n") # add 1 if you start from zero
permuteLengthMin = lineNos
permuteLengthMax = lineNos
# sticking to default "seedlisti.txt" i for infinite
oName = "seedlisti.txt"
# open the list from file specified and ignore the \n at the end
with open(inputFileName) as f: # open the list from file specified and ignore the \n at the end
wordlist = f.read().splitlines()
# Note, if the text file has 2 words on one line it will treat it as one, eg "hello world" is 1 item, but with a delimiter (,) as on 1 line "hello", "world" is 2 items.
f.close() ## Save RAM, close the file!
## ## ## STEP 2: PERMUTE the wordlist ## ## ## -----------------------------------------------
print ("Calculating....\n")
loopz = 0
while int(permuteLengthMin+loopz)<= int(permuteLengthMax):
tic = time.perf_counter() # ** Start the timer
with open(oName, 'w') as outfile:
for sent in it.permutations(wordlist, int(permuteLengthMin+loopz)):
outfile.write(f"{' '.join(sent)}\n") # Save to text file as a list of words
toc = time.perf_counter() # ** Stop the timer
print("Calculation of permutation of length:",int(permuteLengthMin+loopz), f", in {toc - tic:0.4f} seconds, or ", ((toc-tic)/60), " minutes") # the 0.4f means 4 decimal places
loopz = int(loopz + 1)
print ("\t RESULTS in " + oName + "\n")
## NOW ARCHIVE THE SEEDLISTi.TXT FILE FOREVER
fileToArchive = time.strftime("Date_%Y_%m_%d_@_Time_%Hh_%Mm_%Ss")
print (fileToArchive)
SeedlistArchive = "Seedlist_Archive_"
fileToArchive2 = SeedlistArchive+fileToArchive+".txt"
print (fileToArchive2)
with open('seedlisti.txt','r') as firstfile, open(fileToArchive2,'a+') as secondfile:
# read content from first file
for line in firstfile:
# write content to second file
secondfile.write(line)
# now move the file to archive
newPath = shutil.move(fileToArchive2, 'archives')
# permuteri() Obviously dont call it twice from the infinitehunter.py program