-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDictionaryHacker.py
51 lines (44 loc) · 1.73 KB
/
DictionaryHacker.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
import VigenereDecrypt
import DetectLanguage
import re
import sys
import Constants
def loadingBar(count, total, size):
percent = float(count) / float(total) * 100
sys.stdout.write("\r" + str(int(count)).rjust(3, '0') + "/" + str(int(total)).rjust(3, '0'))
def openfile(lang):
dictionary = Constants.pick_dict(lang)
with open(dictionary, encoding="utf-8") as f:
dictfile = f.readlines()
return dictfile
def dictionaryhack(lang, word):
pattern = re.compile('\W')
word_dict = {}
dictfile = openfile(lang)
count = len(dictfile)
iterator = 0
for line in dictfile:
loadingBar(iterator, count, 1)
iterator += 1
if len(word) < len(line):
continue
line = line.strip()
line = re.sub(pattern, '', line)
deciphered_word = VigenereDecrypt.decryption(lang, word, line)
buffer_word = deciphered_word.split()
isEnglish = DetectLanguage.DetectLanguage(lang, buffer_word)
if isEnglish > 0.6:
word_dict[line] = isEnglish
print(" Слово:", line, ", вероятность связности текста: ", isEnglish, ';расшифровка:',
deciphered_word)
if isEnglish > 0.8:
choice = 0
print("Найден наиболее подходящий ключ:", line, ";расшифровка - ", deciphered_word)
print("Продолжить? (y/n)")
choice = input()
while choice != "y" and choice != "n":
print("(y/n)")
choice = input()
if choice == "n":
break
return VigenereDecrypt.decryption(lang, word, max(word_dict))