Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_best_shifts(wordlist, text):
- find_best_shifts_rec(wordlist, text, 0)
- return list_o_shifts
- list_o_shifts = []
- def find_best_shifts_rec(wordlist, text, start):
- global list_o_shifts
- just_added = ()
- for shift in range(0, 27):
- s = text[:start] + apply_shift(text[start:], shift)
- print "s:", s
- possible_word = ""
- if " " not in s[start:]:
- possible_word = s[start:]
- if is_word(wordlist, possible_word):
- list_o_shifts = []
- print "decoded word:", possible_word
- list_o_shifts.append((start, shift))
- print list_o_shifts
- for n in range(start, len(s)):
- if s[n] == " ":
- possible_word = s[start:n]
- if is_word(wordlist, possible_word):
- print "decoded word:", possible_word
- find_best_shifts_rec(wordlist, s, (n + 1))
- if len(list_o_shifts) > 0:
- just_added = list_o_shifts[0]
- if just_added[0] != start:
- list_o_shifts.insert(0, (start, shift))
- print "list of shifts:", list_o_shifts
- break
- else:
- break
Advertisement
Add Comment
Please, Sign In to add comment