forked from Th4nat0s/Chall_Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindword.py
executable file
·64 lines (44 loc) · 1.55 KB
/
findword.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
#!/usr/bin/python
# v 0.1
# Copyleft Thanat0s
# http://Thanat0s.trollprod.org
#
# Licence GNU GPL
import re
import sys
import string
import unicodedata
def removeAccentedChars(s):
u = unicode( s, "utf-8" )
return unicodedata.normalize('NFKD',u).encode('ascii','ignore')
if __name__ == '__main__':
candidates = []
letters, length = sys.argv[1:]
length = int(length)
column = (80 - length) / length
lettercount = []
for char in "".join([c for i,c in enumerate(letters) if i==letters.find(c)]):
lettercount.append( [char, letters.count(char)])
regex = re.compile ("^["+ letters + "]{" + str(length) + "}$")
with open('/usr/share/dict/french', 'r') as f:
for lines in f.readlines():
lines = removeAccentedChars(lines).rstrip() # Remove crlf and accents
if regex.match(lines): # find candidate with the regex
linletcount = [] # Count the letters in the candidate.
for char in "".join([c for i,c in enumerate(lines) if i==lines.find(c)]):
linletcount.append( [char, lines.count(char)])
invalid = False
for letterC in linletcount: # Pour Chaque source
for letterS in lettercount: # Pour chaque dest
if letterS[0] == letterC[0]: # trouve la lettre...
if letterS[1] < letterC[1]: # y a t'il le meme nombre de letttres
invalid = True
if invalid == False:
candidates.append (lines)
i=0
for candidate in candidates:
i = i + 1
print candidate,
if i > column:
i=0
print "\n",