私には2つの機能があります。1つ目は、指定されたテキストをCaesar暗号化するコーダーを作成します。
def buildCoder(shift):
lettersU=string.ascii_uppercase
lettersL=string.ascii_lowercase
dic={}
dic2={}
for i in range(0,len(lettersU and lettersL)):
dic[lettersU[i]]=lettersU[(i+shift)%len(lettersU)]
dic2[lettersL[i]]=lettersL[(i+shift)%len(lettersL)]
dic.update(dic2)
return dic
2つ目は、特定のテキストにコーダーを適用します。
def applyCoder(text, coder):
cipherText=''
for l in text:
if l in coder:
l=coder[l]
cipherText+=l
return cipherText
問題のパート3では、ラッパーを作成するように求められますが、コーディングに慣れていないため、これら2つの関数を使用するラッパーをコーディングする方法がわかりません。
def applyShift(text, shift):
"""
Given a text, returns a new text Caesar shifted by the given shift
offset. Lower case letters should remain lower case, upper case
letters should remain upper case, and all other punctuation should
stay as it is.
text: string to apply the shift to
shift: amount to shift the text (0 <= int < 26)
returns: text after being shifted by specified amount.
"""