我有下面的程序,它被傳遞到另一個函數,它只是打印出原始和加密的消息。我想知道我可以簡化這個程序,特別是「匹配=拉鍊」和「變化=(減少(拉姆達」行。如果可能的話要做到這一點,而不使用lambda,哪能?在Python中簡化Vigenere密碼程序
from itertools import cycle
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"]
def vigenereencrypt(message,keyword):
output = ""
match = zip(message.lower(),cycle(keyword.lower()))
for i in match:
change = (reduce(lambda x, y: alphabet.index(x) + alphabet.index(y), i)) % 26
output = output + alphabet[change]
return output.lower()
太棒了。我<3。 – kpie