ricketybridge

Untitled

Apr 8th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. def find_best_shifts_rec(wordlist, text, start):
  2.     for shift in range(0, 27):
  3.         print "Shift:", shift
  4.         s = text[:start] + apply_shifts(text[start:], [(0, shift)])
  5.         print "s:", s
  6.         possible_word = ""
  7.         n_index = 0
  8.         for n in s[start:]:
  9.             n_index = s.index(n)
  10.             if n == " ":
  11.                 possible_word = s[start:n_index]
  12.                 print "Possible word:", possible_word
  13.                 if is_word(wordlist, possible_word):
  14.                     print "Decoded word:", possible_word
  15.                     print "(start, shift):", (start, shift)
  16.                     return find_best_shifts_rec(wordlist, s, n_index + 1)
  17.                 else:
  18.                     break
  19.             elif (n_index + 1) == len(s):
  20.                 if is_word(wordlist, possible_word):
  21.                     return (start, shift)
  22.                     print "(start, shift):", (start, shift)
Advertisement
Add Comment
Please, Sign In to add comment