MIT600 Open Courseware pset4帮助请求

时间:2017-07-14 20:09:49

标签: python encryption caesar-cipher

我最近一直在使用麻省理工学院600的开放课件版本而且我已经停留在pset4上了。在这个pset中,我们正在尝试使用Caesar密码。我们必须实现既可以进行单层加密也可以进行多层加密和解密的功能。我正在努力解决多层解密问题。以下是处理解密过程的函数代码。

def find_best_shifts_rec(wordlist,text,start):

for number in range(CHARACTERS):    

    new_text = text[start:] + apply_shift(text[:start], number)

    #look for spaces in the encrypted section of text
    found_space = new_text[start:].find(' ')

    #if space occurs after out starting point
    if found_space > start:

        #if the text between the start and the space are viable words
        if is_word(wordlist, new_text[start:found_space]):
            next_check = find_best_shifts_rec(wordlist, new_text, \
                found_space)

            #if we find another list of encryption keys
            if not next_check == None:
                return [(found_space, number)].append(next_check)

    #if no spaces found
    else:

        #if from start to end of string is a word
        if is_word(wordlist, new_text[start:]):
            return [(start, number)]

#if this encryption cannot possibly contain an answer
return None

我还将包含指向我的完整文件的链接,教授提供的伪代码以及pset的规范。我遇到了非常奇怪的问题,每当代码运行时,我总会得到一个NoneType错误。感谢您愿意给予的任何帮助!

完整文件(ps4.py)和伪代码(ps4-pseudo.txt):https://github.com/chriswolfdesign/MIT600OCW/tree/master/master/psets/pset4

规格: https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/unit-2/lecture-10-hashing-and-classes/MIT6_00SCS11_ps4.pdf

0 个答案:

没有答案