diff --git a/main.py b/main.py index 6899408..1990023 100644 --- a/main.py +++ b/main.py @@ -84,18 +84,21 @@ def wordlist_to_morse(dictionary_latin): # dictionary_latin = einsprachiges Wö return result -def guess_vocabs_BUT_AWESOME(cipher, dictionary): # cipher: zu entschlüsselnde Chiffre, dictionary: Wortliste im Morsecode +def guess_vocabs_BUT_AWESOME(cipher, dictionary, min_vocab_len = 0, max_word_count = 0): # cipher: zu entschlüsselnde Chiffre, dictionary: Wortliste im Morsecode length = len(cipher) + if max_word_count == 0: max_word_count = length # Bei Standardwert 0 wird max_word_count so hoch gesetzt, dass es de facto keine Einschränkung macht. phrase_kit = [[] for x in range(length + 2, 0, -1)] phrase_kit[length + 1] = " " print(phrase_kit) for i in range(length, 0, -1): # vom hintersten Buchstaben an nach vorne wird die Chiffre in immer längere Schnipsel gehackt query = cipher[i - 1:length] # query: Schnipsel der Chiffre wird auf sinnvolle Worte getestet for vocab in dictionary: - if vocab[0] == query[0:len(vocab[0])]: # wird ein passendes Wort gefunden und gibt es im phrase-kit Worte, die das gefundene Wort zur Länge des zu prüfenden Wortes ergänzen... - print("i = ", i, " Appending to ", vocab[1]) + if vocab[0] == query[0:len(vocab[0])] \ + and len(vocab[1]) >= min_vocab_len: # wird ein passendes Wort gefunden und gibt es im phrase-kit Worte, die das gefundene Wort zur Länge des zu prüfenden Wortes ergänzen... + print("i = ", i, " Appending to ", vocab[1], " len = ", len(vocab[1])) for phrase in phrase_kit[i + len(vocab[0])]: - phrase_kit[i].append(vocab[1] + " " + phrase) + if phrase.count(" ") <= max_word_count: + phrase_kit[i].append(vocab[1] + " " + phrase) return phrase_kit @@ -116,17 +119,20 @@ def deciphering_1(): dictDE_file = open("wordlist-german.txt", "r", encoding="utf-8") dictEN_file = open("wordlist-english.txt", "r", encoding="utf-8") +dictEN_short_file = open("corncob_caps.txt", "r", encoding="utf-8") reader = csv.reader(dictDE_file) dictDE = [row[0].upper() for row in reader] reader = csv.reader(dictEN_file) dictEN = [row[0].upper() for row in reader] -dictionary = dictDE +reader = csv.reader(dictEN_short_file) +dictEN_short = [row[0].upper() for row in reader] +dictionary = dictEN_short #dictionary = ["FEMINIST", "TERESA", "INA", "ES", "MIT", "SEIT", "ID"] dictMORSE = wordlist_to_morse(dictionary) print("dictMORSE erstellt") -phrase_kit = guess_vocabs_BUT_AWESOME(morse_cipher, dictMORSE) +phrase_kit = guess_vocabs_BUT_AWESOME(morse_cipher, dictMORSE, max_word_count=3) for result in phrase_kit[1]: print(result)