ricketybridge

Untitled

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