Im對vigenere密碼的編碼/解碼編程有問題。我只是應該使用列表,字典和循環。 編輯:我加入瞭解密我有。 GetCharList()只是獲取一個包含字母表的列表。我不知道什麼是錯誤的,它使decrpyt的輸出不是原始消息。Vigenere Cipher Python 2.0
def encryptVig(msg, keyword):
alphabet = getCharList() #Get char list is another function which creates a list containing a - z
key = keyword.upper()
keyIndex = 0
dicList = []
for symbol in msg:
num = alphabet.find(key[keyIndex])
if num != -1:
num += alphabet.find(key[keyIndex])
alphabet.find(key[keyIndex])
num%= len(alphabet)
if symbol.isupper():
dicList.append(alphabet[num])
elif symbol.islower():
dicList. append(alphabet[num].lower())
keyIndex += 1
if keyIndex == len(key):
keyIndex = 0
else:
dicList.append(symbol)
return " " .join(dicList)
def decryptVig(msg, keyword):
getCharList()
key = keyword.upper()
keyIndex = 0
dicList = []
for symbol in msg:
num = alphabet.find(key[keyIndex])
if num != -1:
num -= alphabet.find(key[keyIndex])
alphabet.find(key[keyIndex])
num%= len(alphabet)
if symbol.isupper():
dicList.append(alphabet[num])
elif symbol.islower():
dicList. append(alphabet[num].lower())
keyIndex -= 1
if keyIndex == len(key):
keyIndex = 0
else:
dicList.append(symbol)
return " " .join(dicList)
你有什麼問題? – Schleis
所以基本上我們不能運行你的東西,你有一些問題,但你不告訴我們它是什麼?! – Grapsus
當我編碼時,它會產生一個輸出,例如Q O Q O O Q 當我用解碼功能對它進行解碼時,解碼功能與+進入基本相同 - 反向密碼,它不解密信息。 – SpicehTuna