我知道這聽起來像是一個常見的問題,而且很簡單,但我無法理解它。
我在下面粘貼了我的代碼。我將此代碼稱為程式 1
def openCipher():
cipher = Toplevel()
cipher.title("decryptt - CIPHER")
cipherLabel = Label(cipher, text="cipher").pack()
cipherEntry = Entry(cipher, width=20, borderwidth=5) #separating pack now allows you to use get() on this
cipherEntry.pack()
cipherChoices = [
("Binary","Binary"),
("Caesar","Caesar"),
("Hexadecimal","Hexadecimal"),
("Atbash","Atbash"),
("Letter-to-Number","Letter-to-Numbe")
]
cipherType = StringVar()
cipherType.set("Binary")
for text, cipherChoice in cipherChoices:
Radiobutton(cipher, text=text, variable=cipherType, value=cipherChoice).pack()
cipherButton = Button(cipher, text="Cipher", padx=10, pady=5, command=lambda: ciphering(cipherEntry.get(), cipherType.get())).pack() #lambda allows you to pass arguments to functions
quitButton = Button(cipher, text="Exit Cipher", padx=10, pady=5, command=cipher.destroy).pack()
def openDecipher():
decipher = Toplevel()
decipher.title("decryptt - DECIPHER")
decipherLabel = Label(decipher, text="decipher").pack()
decipherEntry = Entry(decipher, width=20, borderwidth=5) #separating pack now allows you to use get() on this
decipherEntry.pack()
decipherButton = Button(decipher, text="Decipher", padx=10, pady=5, command=lambda:deciphering(decipherEntry.get())).pack() #lambda allows you to pass arguments to functions
quitButton = Button(decipher, text="Exit Decipher", padx=10, pady=5, command=decipher.destroy).pack()
# This is the function that is suppose to split the input from cipherEntry into individual characters in an array.
def ciphering(input,choice):
ciphering = Toplevel() #needed to add new label to
cipherLabeling = Label(ciphering, text = "You have inputted '" input "'").pack()
seperatedWord = list(input)
cipherLabeling = Label(ciphering, text = seperatedWord[:]).pack()
seperatedWordLength = len(seperatedWord)
cipherLabeling = Label(ciphering, text = seperatedWordLength).pack()
selection = Label(ciphering, text = choice).pack()
quitButton = Button(ciphering, text="Exit", padx=10, pady=5, command=ciphering.destroy).pack()
并將此代碼作為程式 2
while counter < length:
if seperatedWord[counter] == lexicon[lexiconPlacing]:
print("letter match: " seperatedWord[counter])
seperatedWord[counter] = cipherArray[lexiconPlacing]
counter = counter 1
lexiconPlacing = 0
# else:
# print("letter don't match")
lexiconPlacing = lexiconPlacing 1
# else:
# print("no")
print(seperatedWord)
lexiconPlacing = 0
counter = 0
print('-'.join(seperatedWord))

我需要幫助的是如何制作它,以便在單擊上圖中的“密碼”按鈕時訪問程式 2 中的 while 回圈。我有它,以便在文本框中輸入輸入并選擇密碼型別到另一個視窗,但我不知道如何使用 make 它以便將它們輸入到函式中以及如何實際使函式在 Tkinter 視窗中作業.我發現制作它特別困難,以便陣列在程式 2 中使用(cipherType,這是選擇的密碼,因此如果他們使用單選按鈕選擇二進制,則使用的陣列將是二進制的。我不知道如何使用他們選擇的單選按鈕將其更改為特定陣列)。
我已經嘗試過這樣,無論他們選擇什么選項,它都會將與之關聯的陣列復制到一個通用陣列,即 cipherType。但這不起作用,因為我已經讀過,如果不使用 numpy 或類似的東西,您將無法真正復制陣列。
基本上,我需要幫助的是如何制作它,以便我可以使用來自單選按鈕的輸入來更改正在呼叫的函式內部的陣列,該函式會加密用戶輸入的任何內容。然后打開另一個顯示結果的視窗。

提前感謝任何幫助或給我任何提示的人:)
uj5u.com熱心網友回復:
我無法復制您的代碼,因為它不完整。但我認為一個視窗足以加密一個單詞。對于解密,您可以簡單地為加密字添加另一個輸入欄位。所有的加密/解密魔法都將在幕后,在函式中發生。我將嘗試描述加密程式的邏輯。
在程式開發中,您必須“從上到下”。
- 您需要定義所有五個勒索軟體功能:
def binary_cipher(world):
print(f'binary {world}')
return encrypted_word
def caesar_cipher(world):
print(f'caesar {world}')
return encrypted_word
# .....
陣列只是 python 串列。
- 現在我們需要根據選定的單選按鈕選擇所需的功能。
def choice_encryption(cipher_type, cipher_entry):
method = cipher_type.get()
entr = cipher_entry.get()
if method == 'binary':
enc_word = binary_cipher(entr)
elif method == 'caesar':
enc_word = caesar_cipher(entr)
# .......
在先前輸入的單詞之后,在輸入欄位中輸出加密的單詞。
使用“密碼”按鈕,您可以使用兩個 StringVar 變數呼叫 choice_encryption 函式。
命令 = lambda:choice_encryption(cipherType,cipherEntry)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/487194.html
