def rotate(n,xs): return xs[0:len(xs)-n] + xs[len(xs)-n:] Some Notes on Cipher Program n = 4 xs = [1,2, 3,4,5,6] [3,4,5,6, 1,2] n = 6 xs = [1,2,3,4, 5,6,7,8,9,10] where should I slice the original list? at this index: len(xs)-n xs[0:len(xs)-n] len(xs) = 6 n = 4 2 xs[len(xs)-n] xs[0:len(xs)-n] + xs[len(xs)-n:] es = table_from_corpus() os = frequencies(s) chisqr(rotate(0,os),es) = 26.92 chisqr(rotate(1,os),es) = 100.22 ... chisqr(rotate(9,os),es) = 8.2 ... chisqr(rotate(25,os),es) = 92.22 0 1 ? 25 similarity_list = [26.92,100.22, ..., 8.2, ..., 92.22] m = 8.2 def crack(s): # input s is the encoded text es = table_from_corpus() os = frequencies(s) similarity_list = chisquare_statistic(os,es) m = min(similarity_list) shift = similarity_list.index(m) return encode(-shift,s) [ (2,'Red'), (3,'Blue'), (1,'Green') ] result = [(1,'Green'), (2,'Red'), (3,'Blue'), (3,'Purple')] max_vote = result[-1][0] [('Red',2), ()] f(x) = x*x answer = f(5)