1

我有一个程序可以使用密钥对消息进行编码和解码,但我想让它看起来更漂亮、更专业。我的代码如下:

from random import seed, shuffle
#Encoder Function
def Encoder(user_input,SEED):
    user_input = user_input.lower()
    letter = ["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']
    Letter_code = {"a":0,"b":1,"c":2,"d":3,"e":4,"f":5,"g":6,"h":7,"i":8,"j":9,"k":10,'l':11,'m':12,'n':13,'o':14,'p':15,'q':16,'r':17,'s':18,'t':19,'u':20,'v':21,'w':22,'x':23,'y':24,'z':25}
    code = ["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',]
    n = []
    seed(SEED)
    shuffle(code)
    for letter in user_input:
        for let in letter:
            if letter != " ":
                if letter == let:
                    first = Letter_code[let]
                    n.append(code[first])
            else:
                n.append("~")
    return ''.join(n)
#Decoder Function
def Decoder(user_input,SEED):
    user_input = user_input.lower
    key_list = ["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']
    final = ["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']
    seed(SEED)
    shuffle(key_list)
    key_code = {}
    z = 0
    n = []
    for key in key_list:
        key_code[key] = z
        z += 1
    for let in user_input:
        if let != "~":
            for Ke in key_list:
                if let == Ke:
                    a = key_code[Ke]
                    n.append(final[a])
        else:
            n.append(" ")
    return ''.join(n)

我想要一个有两个输入框的 gui,一个用于消息,另一个用于密钥,我希望它有两个按钮,一个会说编码,另一个会说解码。以及 gui 中的一个位置,最终消息将被打印并可供用户复制。如果有人可以帮助我,将不胜感激

4

1 回答 1

0

遵循林间空地教程可能会对您有所帮助。

  1. http://www.overclock.net/t/342279/tutorial-using-python-glade-to-create-a-simple-gui-application
  2. https://wiki.gnome.org/Glade/Tutorials
  3. http://www.pygtk.org/articles/pygtk-glade-gui/Creating_a_GUI_using_PyGTK_and_Glade.htm

至于将.py转换为exe,您可以使用py2exe,请看一下这个答案 - https://stackoverflow.com/a/14165470/2689986

于 2013-11-13T11:18:02.750 回答