我的程序中的加密方法沒有正確加密。我以為我明白了為什么要使用調(diào)試模式;這是因?yàn)樗鼘卧~之間的空格讀取為必須加密的內(nèi)容。所以我嘗試輸入一條沒有空格的消息,但它仍然沒有正確輸出。我認(rèn)為問題在于帶有鍵的 if 語句。我嘗試將行注釋掉,更改語句,將 if 語句更改為 for 循環(huán),但它仍然不正確。def main(): vig_square = create_vig_square() message = input("Enter a multi-word message with punctuation: ") input_key = input("Enter a single word key with no punctuation: ") msg = message.lower() key = input_key.lower() coded_msg = encrypt(msg, key, vig_square) print("The encoded message is: ",coded_msg) print("The decoded message is: ", msg) def encrypt(msg,key,vig_square): coded_msg = "" key_inc = 0 for i in range(len(msg)): msg_char = msg[i] if key_inc == len(key)-1: key_inc = 0 key_char = key[key_inc] if msg_char.isalpha() and key_char.isalpha(): row_index = get_row_index(key_char,vig_square) col_index = get_col_index(msg_char,vig_square) coded_msg = coded_msg+vig_square[row_index][col_index] else: coded_msg = coded_msg + " " key_inc = key_inc+1 return coded_msg 但是我的編碼信息是:epr iloyo sif plvqoh
Python Vigenere Cipher Encrypt 方法未正確加密
慕運(yùn)維8079593
2022-05-19 18:54:28