回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<pre><code>def caesar(plaintext,shift):
alphabet=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#Create our substitution dictionary
dic={}
for i in range(0,len(alphabet)):
dic[alphabet[i]]=alphabet[(i+shift)%len(alphabet)]
#Convert each letter of plaintext to the corrsponding
#encrypted letter in our dictionary creating the cryptext
ciphertext=("")
for l in plaintext.lower():
if l in dic:
l=dic[l]
ciphertext+=l
return ciphertext
#Example useage
plaintext="the cat sat on the mat"
print "Plaintext:", plaintext
print "Cipertext:", (caesar(plaintext,29))
</code></pre>
<p>cipertext只打印一个字母,而不是在caesar shift中打印“明文”变量。我要它把整个句子打印出来。在</p>
<p>谢谢</p>