【发布时间】:2018-08-31 02:47:08
【问题描述】:
我应该创建一个使用单词作为加密密钥的程序,最终的行为是这样的
$ python vigenere.py
Type a message:
The crow flies at midnight!
Encryption key:
boom
Uvs osck rmwse bh auebwsih!
这是Vigenere cipher的链接
我的主要问题是它的加密方面。
def vigenere_cipher(plaintext, key):
encrypted_string = ''
for i in range(len(key)):
# loop over plaintext by index
plaintextVal = ord(plaintext)
# if character in plaintext is alpha do the following:
keyVal = ord(key[i])
keyVal = keyVal - 97
# get alphabet position for character in key
plaintextChar += chr(keyVal + plaintextVal)
if plaintextVal >= ord('z')
#get alphabet position for character in plaintext
plaintextVal = plaintextVal - 26
# rotate character from plaintext with a character from the key
# convert new position back to a character if you haven't done it already
# concatenate new character to an encrypted string
print PlaintextVal
return encrypted_string
我遇到了一堆无效的语法错误,我对如何修复代码感到困惑。
提前致谢!
【问题讨论】: