Note that there are some explanatory texts on larger screens.

plurals
  1. POmultilevel caesar cipher
    primarykey
    data
    text
    <p>Hey, I'm trying to decode a multilevel Caesar cipher. By that I mean a string of letters could have been shifted several times, so if I say apply_shifts[(2,3),(4,5)], that means I shift everything from the 2nd letter by 3 followed by everything from the 4th letter by 5. Here's my code so far.</p> <pre><code>def find_best_shifts_rec(wordlist, text, start): """ Given a scrambled string and a starting position from which to decode, returns a shift key that will decode the text to words in wordlist, or None if there is no such key. Hint: You will find this function much easier to implement if you use recursion. wordlist: list of words text: scambled text to try to find the words for start: where to start looking at shifts returns: list of tuples. each tuple is (position in text, amount of shift) """ for shift in range(27): text=apply_shifts(text, [(start,-shift)]) #first word is text.split()[0] #test if first word is valid. if not, go to next shift if is_word(wordlist,text.split()[0])==False: continue #enter the while loop if word is valid, otherwise never enter and go to the next shift i=0 next_index=0 shifts={} while is_word(wordlist,text.split()[i])==True: next_index+= len(text.split()[i]) i=i+1 #once a word isn't valid, then try again, starting from the new index. if is_word(wordlist,text.split()[i])==False: shifts[next_index]=i find_best_shifts_rec(wordlist, text, next_index) return shifts </code></pre> <p>My problems are</p> <p>1) my code isn't running properly and I don't understand why it is messing up (it's not entering my while loop) and 2) I don't know how to test whether none of my "final shifts" (e.g. the last part of my string) are valid words and I also don't know how to go from there to the very beginning of my loop again.</p> <p>Help would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload