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