我最近一直在使用麻省理工学院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