• 2022秋季信息安全实验1


    2022秋季信息安全实验1-密码与隐藏技术1

    实验1.1

    在这里插入图片描述
    (1) 加密后的密文:vhfxulwb
    (2) 解密函数:d(a)=(a-k+26)mod 26
    (3) 编程实现:界面类似于下图中的界面,语言工具语言不限,但要说明开发运行环境,如Python3、VC6、Java SE 8等等。
    开发运行环境说明:Python3

    import PySimpleGUI as simpleGui
    import datetime
    
    
    def dealMainWindowOpenWindowEvent(window2):
        try:
            if not window2:
                window2 = make_window2()
                window2.make_modal()  # 这行代码把当前窗口设置为有模式的
        except Exception as result:
            print("函数 dealMainWindowEvent 捕捉到异常:%s" % result)
        return window2
    
    
    def dealMainWindowEncryptEvent(values):
        try:
            text = values['keyMainWindowPlaintext']
            if text.strip() == "":
                simpleGui.popup_error("提示", "请先输入明文!")
            else:
                # simpleGui.popup("提示", "请自己实现加密函数!")
                s=""
                text=list(map(str,text))
                for i in range(len(text)):
                    text[i]=chr((ord(text[i]) - ord('a') + int(values['keyMainWindowKey'])) % 26 + ord('a'))
                    s+=text[i]
                return s
    
        except Exception as result:
            print("函数 dealMainWindowEvent 捕捉到异常:%s" % result)
    
    def dealMainWindowDecryptEvent(values):
        try:
            text = values['keyMainWindowCiphertext']
            if text.strip() == "":
                simpleGui.popup_error("提示", "请先输入密文!")
            else:
                # simpleGui.popup("提示", "请自己实现加密函数!")
                s = ""
                text = list(map(str, text))
                for i in range(len(text)):
                    text[i] = chr((ord(text[i]) - ord('a') -int(values['keyMainWindowKey'])+26) % 26 + ord('a'))
                    s += text[i]
                return s
    
        except Exception as result:
            print("函数 dealMainWindowEvent 捕捉到异常:%s" % result)
    
    def dealWindow2OkEvent(window2, values):
        newText = ""
        try:
            newText = values['keyWindow2ulText']
            window2.close()
            window2 = None
        except Exception as result:
            print("函数 dealWindow2Event 捕捉到异常:%s" % result)
        return window2, newText
    
    
    def make_window2():
        try:
            # 创建 window2 布局
            window2Layout = [
                [simpleGui.Text('文本'), simpleGui.Input('新窗口默认文本 hello gui。', key='keyWindow2ulText')],
                [simpleGui.Button('确定', key='keyWindow2Ok'), simpleGui.Button('取消', key='keyWindow2Cancel')]
            ]
            window2 = simpleGui.Window("打开新窗口", window2Layout, finalize=True)
            return window2
        except Exception as result:
            print("make_window2 捕捉到异常:%s" % result)
    
    
    def main():
        try:
            # 创建 mainWindow 布局
            mainWindowLayout = [
                [simpleGui.Text('明文'), simpleGui.Input(key='keyMainWindowPlaintext', size=(80, 1)), ],
                [simpleGui.Text('密钥'), simpleGui.Input(key='keyMainWindowKey', size=(80, 1)), ],
                [simpleGui.Text('密文'), simpleGui.Input(key='keyMainWindowCiphertext', size=(80, 1)), ],
                [simpleGui.Text('文本'), simpleGui.Multiline(key='keyMainWindowMulText', size=(80, 8))],
                [simpleGui.Button('加密', key='keyMainWindowEncrypt'),
                 simpleGui.Button('解密', key='keyMainWindowDecrypt'),
                 simpleGui.Button('打开新窗口', key='keyMainWindowOpenWindow'), ],
                [simpleGui.Button('确定', key='keyMainWindowOk'), simpleGui.Button('取消', key='keyMainWindowCancel')],
            ]
    
            # 创建窗口,引入布局,并进行初始化。
            mainWindow = simpleGui.Window('对称加密演示程序', layout=mainWindowLayout, finalize=True)
    
            # 暂时先不创建window2
            window2 = None
    
            # 创建一个事件循环,否则窗口运行一次就会被关闭。
            while True:
                window, event, values = simpleGui.read_all_windows()
                print(window, event, values)  # 可以打印一下着看变量的内容
                if window == mainWindow:
                    if event in (simpleGui.WIN_CLOSED,  'keyMainWindowOk', 'keyMainWindowCancel'):
                        break
                    elif event == 'keyMainWindowOpenWindow':
                        window2 = dealMainWindowOpenWindowEvent(window2)
                    elif event == 'keyMainWindowEncrypt':
                        min=dealMainWindowEncryptEvent(values)
                        mainWindow['keyMainWindowCiphertext'].update(min)
                    elif event == 'keyMainWindowDecrypt':
                         # simpleGui.popup("提示", "请自己实现解密函数!")
                         max=dealMainWindowDecryptEvent(values)
                         mainWindow['keyMainWindowMulText'].update(max)
                if window == window2:
                    if event in (simpleGui.WIN_CLOSED, 'keyWindow2Cancel'):
                        window2.close()
                        window2 = None
                    elif event == 'keyWindow2Ok':
                        window2, newText = dealWindow2OkEvent(window2, values)
                        text = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "\n从window2获得文本:\n" + newText
                        mainWindow['keyMainWindowMulText'].update(text)
            # 关闭窗口
            mainWindow.close()
            if window2 is not None:
                window2.close()
        except Exception as result:
            print("函数 main 捕捉到异常:%s" % result)
    
    
    if __name__ == '__main__':
        main()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126

    实验1.2

    在这里插入图片描述
    (1) 加密后的密文:hrlnedkz
    (2) 解密函数:d=(9(m-5)) mod 26*
    (3) 编程实现:界面类似于下图中的界面,语言工具语言不限,但要说明开发运行环境,如Python3、VC6、Java SE 8等等。
    开发运行环境说明:Python3

    import PySimpleGUI as simpleGui
    import datetime
    
    
    def dealMainWindowOpenWindowEvent(window2):
        try:
            if not window2:
                window2 = make_window2()
                window2.make_modal()  # 这行代码把当前窗口设置为有模式的
        except Exception as result:
            print("函数 dealMainWindowEvent 捕捉到异常:%s" % result)
        return window2
    
    
    def dealMainWindowEncryptEvent(values):
        try:
            text = values['keyMainWindowPlaintext']
            if text.strip() == "":
                simpleGui.popup_error("提示", "请先输入明文!")
            else:
                # simpleGui.popup("提示", "请自己实现加密函数!")
                s=""
                text=list(map(str,text))
                for i in range(len(text)):
                    text[i]=chr((3*(ord(text[i])- ord('a'))+5) % 26 + ord('a'))
                    s+=text[i]
                return s
    
        except Exception as result:
            print("函数 dealMainWindowEvent 捕捉到异常:%s" % result)
    
    def dealMainWindowDecryptEvent(values):
        try:
            text = values['keyMainWindowCiphertext']
            if text.strip() == "":
                simpleGui.popup_error("提示", "请先输入密文!")
            else:
                # simpleGui.popup("提示", "请自己实现解密函数!")
                s = ""
                text = list(map(str, text))
                for i in range(len(text)):
                    text[i] = chr((((ord(text[i])- ord('a'))-5)*9) % 26 + ord('a'))
                    s += text[i]
                return s
    
        except Exception as result:
            print("函数 dealMainWindowEvent 捕捉到异常:%s" % result)
    
    def dealWindow2OkEvent(window2, values):
        newText = ""
        try:
            newText = values['keyWindow2ulText']
            window2.close()
            window2 = None
        except Exception as result:
            print("函数 dealWindow2Event 捕捉到异常:%s" % result)
        return window2, newText
    
    
    def make_window2():
        try:
            # 创建 window2 布局
            window2Layout = [
                [simpleGui.Text('文本'), simpleGui.Input('新窗口默认文本 hello gui。', key='keyWindow2ulText')],
                [simpleGui.Button('确定', key='keyWindow2Ok'), simpleGui.Button('取消', key='keyWindow2Cancel')]
            ]
            window2 = simpleGui.Window("打开新窗口", window2Layout, finalize=True)
            return window2
        except Exception as result:
            print("make_window2 捕捉到异常:%s" % result)
    
    
    def main():
        try:
            # 创建 mainWindow 布局
            mainWindowLayout = [
                [simpleGui.Text('明文'), simpleGui.Input(key='keyMainWindowPlaintext', size=(80, 1)), ],
                # [simpleGui.Text('密钥'), simpleGui.Input(key='keyMainWindowKey', size=(80, 1)), ],
                [simpleGui.Text('密文'), simpleGui.Input(key='keyMainWindowCiphertext', size=(80, 1)), ],
                [simpleGui.Text('文本'), simpleGui.Multiline(key='keyMainWindowMulText', size=(80, 8))],
                [simpleGui.Button('加密', key='keyMainWindowEncrypt'),
                 simpleGui.Button('解密', key='keyMainWindowDecrypt'),
                 simpleGui.Button('打开新窗口', key='keyMainWindowOpenWindow'), ],
                [simpleGui.Button('确定', key='keyMainWindowOk'), simpleGui.Button('取消', key='keyMainWindowCancel')],
            ]
    
            # 创建窗口,引入布局,并进行初始化。
            mainWindow = simpleGui.Window('对称加密演示程序', layout=mainWindowLayout, finalize=True)
    
            # 暂时先不创建window2
            window2 = None
    
            # 创建一个事件循环,否则窗口运行一次就会被关闭。
            while True:
                window, event, values = simpleGui.read_all_windows()
                print(window, event, values)  # 可以打印一下着看变量的内容
                if window == mainWindow:
                    if event in (simpleGui.WIN_CLOSED,  'keyMainWindowOk', 'keyMainWindowCancel'):
                        break
                    elif event == 'keyMainWindowOpenWindow':
                        window2 = dealMainWindowOpenWindowEvent(window2)
                    elif event == 'keyMainWindowEncrypt':
                        min=dealMainWindowEncryptEvent(values)
                        mainWindow['keyMainWindowCiphertext'].update(min)
                    elif event == 'keyMainWindowDecrypt':
                         # simpleGui.popup("提示", "请自己实现解密函数!")
                         max=dealMainWindowDecryptEvent(values)
                         mainWindow['keyMainWindowMulText'].update(max)
                if window == window2:
                    if event in (simpleGui.WIN_CLOSED, 'keyWindow2Cancel'):
                        window2.close()
                        window2 = None
                    elif event == 'keyWindow2Ok':
                        window2, newText = dealWindow2OkEvent(window2, values)
                        text = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "\n从window2获得文本:\n" + newText
                        mainWindow['keyMainWindowMulText'].update(text)
            # 关闭窗口
            mainWindow.close()
            if window2 is not None:
                window2.close()
        except Exception as result:
            print("函数 main 捕捉到异常:%s" % result)
    
    
    if __name__ == '__main__':
        main()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
  • 相关阅读:
    四种el-table的配置排序方式
    MQ中的坑及高并发下保证接口的幂等性
    在分布式系统中,库存超卖怎么办?
    波奇学Linux:文件系统打开文件
    NAS文件的名称或路径过长导致文件同步被挂起
    【技术积累】Linux中的命令行【理论篇】【八】
    你想知道的ArrayList知识都在这
    torch.mm函数介绍
    C# 如何设计一个好用的日志库?【架构篇】
    Ubuntu安装和配置ssh
  • 原文地址:https://blog.csdn.net/qq_61963074/article/details/126711203