异或加密 并暴力破解测试破解密码可行性

 key = key * (len(plaintext) // len(key)) + key[:len(plaintext) % len(key)]#取整数/余数
    ciphertext=[]
    for i in range(len(plaintext)):
        ciphertext.append(str(ord(plaintext[i])^ord(key[i])))
    key = ','.join(ciphertext)

异或加密 并暴力破解测试破解密码可行性_第1张图片
密码枚举测试
异或加密 并暴力破解测试破解密码可行性_第2张图片

# -*- endoding: utf-8 -*-
# @ModuleName:异或加密
# @Function(功能):
# @Author : 苏穆冰白月晨
# @Time : 2021/1/2 1:11
import time
from  tkinter import *
from PIL import  Image , ImageTk
def a():
    key = i1_2.get()



    f=open('plaintext.txt', encoding='gbk')
    txt=[]

    for line in f:
        txt.append(line.strip())
    plaintext = "".join(txt)

    key = key * (len(plaintext) // len(key)) + key[:len(plaintext) % len(key)]#取整数/余数
    ciphertext=[]
    for i in range(len(plaintext)):
        ciphertext.append(str(ord(plaintext[i])^ord(key[i])))
    key = ','.join(ciphertext)
    # ff = tk.Label(win, text=key)
    ee.insert("end", key)

def b():
    t0 = time.time()

    num = 0
    str = "qwertyuiopasdfghjklzxcvbnm"
    key = i1_22.get()
    key_len = len(key)
    if key_len == 1:
        for i in str:
            num += 1
            key_s = i
            if key_s == key:
                t1 = time.time()
                time_key =  t1 - t0
                i1_22_1.insert("end", time_key)

    if key_len == 2:
        for i in str:
            for j in str:
                num += 1
                key_s = i + j

                if key_s == key:
                    t1 = time.time()
                    time_key = t1 - t0
                    i1_22_2.insert("end", time_key)

    if key_len == 3:
        for i in str:
            for j in str:
                for g in str:
                    num += 1
                    key_s = i + j + g

                    if key_s == key:
                        t1 = time.time()
                        time_key = t1 - t0
                        i1_22_3.insert("end", time_key)
    if key_len == 4:
        for i in str:
            for j in str:
                for g in str:
                    for h in str:
                        num += 1
                        key_s = i + j + g + h

                        if key_s == key:
                            t1 = time.time()
                            time_key = t1 - t0
                            i1_22_4.insert("end",time_key)
    if key_len == 5:
        for i in str:
            for j in str:
                for g in str:
                    for h in str:
                        for m in str:
                            num += 1
                            key_s = i + j + g + h + m

                            if key_s == key:
                                t1 = time.time()
                                time_key = t1 - t0
                                i1_22_5.insert("end", time_key)
    if key_len == 6:
        for i in str:
            for j in str:
                for g in str:
                    for h in str:
                        for m in str:
                            for n in str:
                                num += 1
                                key_s = i + j + g + h + m + n

                                if key_s == key:
                                    t1 = time.time()
                                    time_key = t1 - t0
                                    i1_22_6.insert("end", time_key)
if __name__ == '__main__':
    import tkinter as tk

    win = tk.Tk()
    win.geometry("450x500")

    canvas = Canvas(win)
    canvas.place(x=0, y=0, width=600, height=500)

    win.title("异或加密器")
    photo = PhotoImage(file='666.png')
    canvas.create_image(200,300, image=photo)

    i1_1 = tk.Label(win, text="请输入key", compound = 'center')
    i1_1.place(x=30, y=20, width=80, height=20)

    i1_11 = tk.Label(win, text="请输入key(小写英文字母)")
    i1_11.place(x=30, y=270, width=150, height=20)

    i1_2 = tk.Entry(win, width=15)
    i1_2.place(x=130, y=20, width=100, height=20)

    i1_22 = tk.Entry(win, width=15)
    i1_22.place(x=180, y=270, width=100, height=20)

    button = tk.Button(win,text="加密",width=15,command=a)
    button.place(x=300 ,y=20, width=50, height=20)

    button_jiemi = tk.Button(win, text="枚举密码测试", width=15, command=b)
    button_jiemi.place(x=300, y=270, width=100, height=20)

    ee=tk.Text(win,width=40)
    ee.place(x=40, y=50, width=300, height=150)

    # ee_2 = tk.Text(win, width=40)
    # ee_2.place(x=320, y=50, width=350, height=100)
    i1_11 = tk.Label(win, text="密钥长度")
    i1_11.place(x=60, y=300, width=150, height=20)

    i1_11 = tk.Label(win, text="耗时")
    i1_11.place(x=240, y=300, width=150, height=20)

    i1_11 = tk.Label(win, text="1")
    i1_11.place(x=60, y=330, width=150, height=20)

    i1_22_1 = tk.Entry(win, width=15)
    i1_22_1.place(x=250, y=330, width=150, height=20)

    i1_11 = tk.Label(win, text="2")
    i1_11.place(x=60, y=350, width=150, height=20)

    i1_22_2 = tk.Entry(win, width=15)
    i1_22_2.place(x=250, y=350, width=150, height=20)

    i1_11 = tk.Label(win, text="3")
    i1_11.place(x=60, y=370, width=150, height=20)

    i1_22_3 = tk.Entry(win, width=15)
    i1_22_3.place(x=250, y=370, width=150, height=20)

    i1_11 = tk.Label(win, text="4")
    i1_11.place(x=60, y=390, width=150, height=20)

    i1_22_4 = tk.Entry(win, width=15)
    i1_22_4.place(x=250, y=390, width=150, height=20)

    i1_11 = tk.Label(win, text="5")
    i1_11.place(x=60, y=410, width=150, height=20)

    i1_22_5 = tk.Entry(win, width=15)
    i1_22_5.place(x=250, y=410, width=150, height=20)

    i1_11 = tk.Label(win, text="6")
    i1_11.place(x=60, y=430, width=150, height=20)

    i1_22_6 = tk.Entry(win, width=15)
    i1_22_6.place(x=250, y=430, width=150, height=20)

    win.mainloop()

你可能感兴趣的:(python)