从另一个数组分配数组[加密程序问题]

2024-09-30 22:11:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码[仅与'EncryptString'函数相关]:

from tkinter import *
import time

c = ["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""]
nc = ["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""]
al = ["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"]
at = ["b","m","f","s","c","v","e","l","d","n","t","a","w","g","p","o","r","q","k","h","u","x","i","y","j","z"]

def GoE():
    EnteredText = (e1.get())
    if EnteredText != ".!entry":
        print("Encrypting")
        #try:
        print(EnteredText, e1)
        print("Attempting to Encrypt")
        EnteredText.lower()
        c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], c[10], c[11], c[12], c[13], c[14], c[15], c[16], c[17], c[18], c[19], c[20], c[21], c[22], c[23], c[24], c[25], c[26], c[27], c[28], c[29], c[30], c[31] = EnteredText
        EncryptString()


def Encrypter():
    print("Encrypter Selected")
    screen2.title("Encrypter")
    a = Label(screen2, text="Text to be Encrypted (SUM OF CHARACTERS MUST BE 32)").grid(row=1, column=0)
    e1.grid(row=2, column=0)
    button2 = Button(screen2, text="Enter", command=GoE).grid(row=3, column=0)

def EncryptString():
    count = 0
    letterPos = 0
    poo = 0
    print('1')
    test2 = 0
    while test2 <= 31:
        print(c[test2])
        test2 = test2 + 1
    time.sleep(10)
        while poo <= 31:
            while count <= 31:
                print(str(count))
                if c[count] == al[letterPos]:
                    nc[count] = at[letterPos]
                    print('1.3')
                    print(nc[count])
                else:
                    if letterPos == 25:
                        print('Alphabet Completed')
                        letterPos = 0
                    else:
                        letterPos = letterPos + 1
                        print('1.2')
                count = count + 1
                print('Count = ' + str(count))
            count = 0
            poo = poo + 1
        test = test + 1
    num = 0
    while num <= 31:
        print(nc[num])
        num = num + 1





MenuScreen()

导致错误的主要原因是:

        while poo <= 31:
            while count <= 31:
                print(str(count))
                if c[count] == al[letterPos]:
                    nc[count] = at[letterPos]
                    print('1.3')
                    print(nc[count])
                else:
                    if letterPos == 25:
                        print('Alphabet Completed')
                        letterPos = 0
                    else:
                        letterPos = letterPos + 1
                        print('1.2')
                count = count + 1
                print('Count = ' + str(count))
            count = 0
            poo = poo + 1
        test = test + 1

我个人认为这与:

if c[count] == al[letterPos]:
    nc[count] = at[letterPos]

它应该加密32个字符的文本,并打印在最后。 我试图加密的文本是'abcdefghijklmnopqrstuvxyzssss',它将加密'a'并打印'b',并将加密'ssssss',并输出'kkkkkk'。剩下的就打印成“”,(一个空格)。您可以使用任何代码补丁来尝试检测问题。 我几天来一直想找出一个问题,但解决不了。非常感谢。我不知道我是走错了路还是有点傻。重新开始可能更容易。我认为我没有循环/循环太多,它只循环通过一个字母每个字符输入。我的问题是,我说的对吗?还有什么需要改进的地方吗


Tags: testifcountelsenumatalprint