ricketybridge

Untitled

Apr 10th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. def find_best_shifts(wordlist, text):
  2.     find_best_shifts_rec(wordlist, text, 0)
  3.     return list_o_shifts
  4.  
  5.  
  6. list_o_shifts = []
  7.  
  8. def find_best_shifts_rec(wordlist, text, start):
  9.     global list_o_shifts
  10.     just_added = ()
  11.     for shift in range(0, 27):
  12.         s = text[:start] + apply_shift(text[start:], shift)
  13.         print "s:", s
  14.         possible_word = ""
  15.         if " " not in s[start:]:
  16.             possible_word = s[start:]
  17.             if is_word(wordlist, possible_word):
  18.                 list_o_shifts = []
  19.                 print "decoded word:", possible_word
  20.                 list_o_shifts.append((start, shift))
  21.                 print list_o_shifts
  22.         for n in range(start, len(s)):
  23.             if s[n] == " ":
  24.                 possible_word = s[start:n]
  25.                 if is_word(wordlist, possible_word):
  26.                     print "decoded word:", possible_word
  27.                     find_best_shifts_rec(wordlist, s, (n + 1))
  28.                     if len(list_o_shifts) > 0:
  29.                         just_added = list_o_shifts[0]
  30.                         if just_added[0] != start:
  31.                             list_o_shifts.insert(0, (start, shift))
  32.                             print "list of shifts:", list_o_shifts
  33.                     break
  34.                 else:
  35.                     break
Advertisement
Add Comment
Please, Sign In to add comment