Part1
Problem 1: Encryption
感谢 glhezjnucn 童鞋对本周问题的给力翻译 !
You’ll now write a program to encrypt plaintext into ciphertext using the Caesar cipher. 你现在来写一个函数将使用凯撒密码将明文转为密文。
def buildCoder(shift):
"""
Returns a dict that can apply a Caesar cipher to a letter.
The cipher is defined by the shift value. Ignores non-letter characters
like punctuation, numbers, and spaces.
shift: 0 <= int < 26
returns: dict
"""
### TODO
ciphertext = {}
uppercase_plaintext = [i for i in string.ascii_uppercase]
lowercase_plaintext = [i for i in string.ascii_lowercase]
for i in range(26):
if i < (26 - shift):
ciphertext[uppercase_plaintext[i]] = uppercase_plaintext[i+shift]
else:
ciphertext[uppercase_plaintext[i]] = uppercase_plaintext[i+shift-26]
for i in range(26):
if i < (26 - shift):
ciphertext[lowercase_plaintext[i]] = lowercase_plaintext[i+shift]
else:
ciphertext[lowercase_plaintext[i]] = lowercase_plaintext[i+shift-26]
return ciphertext

本文介绍了MIT 6.00.1x课程中的凯撒密码加密和解密问题。学生需要编写程序实现加密和解密,其中解密部分通过寻找最大化英语单词数的解码方法来确定最佳移位。此外,提供了辅助函数和伪代码以帮助完成解密任务。
最低0.47元/天 解锁文章
1766

被折叠的 条评论
为什么被折叠?



