Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 24th, 2012  |  syntax: None  |  size: 1.16 KB  |  views: 94  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def find_best_shifts_rec(wordlist, text, start):
  2.  
  3.     ### TODO.
  4.     message = text
  5.     #each start check all possible shift
  6.     for shift in xrange (0,27):
  7.         if start >= len(message):
  8.             return recshift#stop when start gets to the end
  9.         newstart = start
  10.         message = message[:start]+apply_shift(message[start:],shift)#part of the message is shifted
  11.         splitted_message = message[start:].split()#split into unchecked words
  12. ##        print 'shift:',shift,'  ',splitted_message
  13.         for word in splitted_message:#check each possible word
  14.             if is_word(wordlist,word):
  15.                 newstart = start + len(word)+1#plus the length of the valid word and a space
  16. ##                print newstart
  17.             else:#quit the loop when the first invalid word comes
  18.                 break
  19.         if newstart > start and start == 0:#add the first (start,shift) pair
  20.             recshift = [(0,shift)]
  21.         if newstart > start and start != 0:
  22.             recshift = recshift + [(start,shift)]#add new (start,shift) pair
  23. ##            print 'after added:',recshift
  24.             return find_best_shifts_rec(wordlist,message,newstart)