浏览器运行环境异常,请检查是否开启本站的JavaScript权限或下载最新版浏览器。
Logo
luas
artikel
komik
lingkaran
Trending
membantu
Masuk
penciptaan
Unduhan Cepat
Sumber Daya
Belajar
Kolom
7
Turun
4
mengumpulkan
Laporkan
membagikan

简单文件加密工具

学习区-技术教程
7
4k
代码来自GitHub,我对其进行了一定的优化和修改,可用于百度网盘防炸。

主程序代码:

import sys
from tkinter import *
from tkinter import filedialog
from tkinter import ttk
import Tautan web(tkinter.ttk)
import threading
from binascii import a2b_hex
from binascii import b2a_hex
import Tautan web(tkinter.messagebox)
import os
import shutil
import Tautan web(tkinter.scrolledtext)
import multiprocessing
from multiprocessing import Queue
from multiprocessing import Process
import base64
from Tautan web(crypto.cipher) import AES
from Tautan web(crypto.random) import get_random_bytes

from i import img


def read(dir,address,length,f):
    Tautan web(f.seek)(address, 0)
    result = Tautan web(f.read)(length)
    result = b2a_hex(result)
    result = Tautan web(bytes.decode)(result)
    return result
def write(write_bytes,dir,address,f):
    try:
        write_bytes = bytes().fromhex(write_bytes)
    except:
        print(write_bytes)
    Tautan web(f.seek)(address, 0)
    result=Tautan web(f.write)(write_bytes)
    return result
def realcode1(dir,mima,mima_len,flagmi):
    def jiamihanshu(mima, readdata, iv):
        secret = mima  # 由用户输入的16位或24位或32位长的初始密码字符串

        # 密钥处理,16的整数倍
        def add_to_16(text):
            while len(text) % 16 != 0:
                text += '\0'
            return (text)
        secret = add_to_16(secret)
        iv = bytes().fromhex(iv)
        cipher = Tautan web(aes.new)(Tautan web(secret.encode)('utf-8'), AES.MODE_CBC, iv)
        data = readdata  # 16beishu
        data = bytes().fromhex(data)
        try :
            encrypt_data = Tautan web(cipher.encrypt)(data)  # 输入需要加密的字符串,注意字符串长度要是16的倍数。16,32,48..
            encrypt_data = Tautan web(bytes.decode)(b2a_hex(encrypt_data))
            return encrypt_data
        except:
            return Tautan web(bytes.decode)(b2a_hex(data))

    def jiemihanshu(mima, readdata, iv):
        secret = mima  # 由用户输入的16位或24位或32位长的初始密码字符串

        def add_to_16(text):
            while len(text) % 16 != 0:
                text += '\0'
            return (text)

        secret = add_to_16(secret)
        iv = bytes().fromhex(iv)  # 随机获取16位变量
        encrypt_data = bytes().fromhex(readdata)
        cipher = Tautan web(aes.new)(Tautan web(secret.encode)('utf-8'), AES.MODE_CBC, iv)
        try:
            decrypt_data = Tautan web(cipher.decrypt)(encrypt_data)
            decrypt_data = Tautan web(bytes.decode)(b2a_hex(decrypt_data))
            return decrypt_data
        except:
            return Tautan web(bytes.decode)(b2a_hex(encrypt_data))

    f = open(dir, "rb+")
    file_stats = Tautan web(os.stat)(dir)
    max = int(file_stats.st_size)
    i = 0
    while True:
        a = read(dir, i,32, f)
        if flagmi == 1:
            abc = jiamihanshu(mima,a,"20060815200608152006081520060815")
        if flagmi == 2:
            abc = jiemihanshu(mima,a,"20060815200608152006081520060815")
        write(abc,dir,i,f)
        i += 1024
        Tautan web(bar1.step)(1024)
        Tautan web(root.update)()
        if i+1024>=(min(max,10000000)):
            Tautan web(f.close)()
            break
def coding(dir,mima,mima_len,flagmi):
    file_stats = Tautan web(os.stat)(dir)
    max = int(file_stats.st_size)
    realcode1(dir,mima,mima_len,flagmi,)
def jiami(dir,save_dir,mima,mima_len):
    Tautan web(shutil.copyfile)(dir,save_dir)
    coding(save_dir,mima,mima_len,1)
def jiemi(dir,save_dir,mima,mima_len):
    Tautan web(shutil.copyfile)(dir, save_dir)
    coding(save_dir,mima,mima_len,2)
def function1():
    global file2,singleflag
    OpenFile = Tk()   #创建新窗口
    Tautan web(openfile.withdraw)()
    file_path2 = Tautan web(filedialog.askopenfilenames)(filetypes=[('加密文件(*.ghl)','.ghl')]) # 获取路径
    Tautan web(a3.configure)(state='normal')
    Tautan web(a3.delete)(0, 'end')
    Tautan web(a3.insert)(INSERT, file_path2)
    Tautan web(a3.configure)(state='disable')
    file2 = file_path2
    singleflag = 1
def function2():
    global file1,singleflag
    OpenFile = Tk()   #创建新窗口
    Tautan web(openfile.withdraw)()
    file_path1 = Tautan web(filedialog.askopenfilenames)() # 获取路径
    Tautan web(a2.configure)(state='normal')
    Tautan web(a2.delete)(0, 'end')
    Tautan web(a2.insert)(INSERT, file_path1)
    Tautan web(a2.configure)(state='disable')
    file1 = file_path1
    singleflag = 1
def functionjia():
    global file1,singleflag
    OpenFile = Tk()  # 创建新窗口
    Tautan web(openfile.withdraw)()
    file_path1 = Tautan web(filedialog.askdirectory)()
    file1 = ()
    for root1, dirs, files in Tautan web(os.walk)(file_path1, topdown=False):
        for a in files:
            newroot = ''
            for evestr in root1:
                if evestr == '\\':
                    newroot+='/'
                else:
                    newroot+=evestr
            file1+=(newroot+'/'+a,)
    Tautan web(a2.configure)(state='normal')
    Tautan web(a2.delete)(0, 'end')
    Tautan web(a2.insert)(INSERT, file_path1)
    Tautan web(a2.configure)(state='disabled')
    singleflag = 0
def functionjie():
    global file2,singleflag
    OpenFile = Tk()  # 创建新窗口
    Tautan web(openfile.withdraw)()
    file_path2 = Tautan web(filedialog.askdirectory)()
    file2 = ()
    for root1, dirs, files in Tautan web(os.walk)(file_path2, topdown=False):
        for a in files:
            newroot = ''
            for evestr in root1:
                if evestr == '\\':
                    newroot += '/'
                else:
                    newroot += evestr
            file2 += (newroot + '/'+a,)
    Tautan web(a3.configure)(state='normal')
    Tautan web(a3.delete)(0, 'end')
    Tautan web(a3.insert)(INSERT, file_path2)
    Tautan web(a3.configure)(state='disabled')
    singleflag = 0
def function3():#jiami
    global file1,log,singleflag
    if singleflag == 0:
        mima = Tautan web(a1.get)()
        newmima = ''
        for i in mima:
            newmima = newmima+str(ord(i))
        mima = newmima
        mima_len = len(mima)
        cha = 1024
        save_dir = Tautan web(filedialog.askdirectory)(initialdir=Tautan web(a2.get)())
        print(save_dir)
        for everypath in file1:
            if save_dir!='':
                Tautan web(log.configure)(state='normal')
                Tautan web(log.insert)(INSERT, '正在加密'+save_dir+everypath[len(Tautan web(a2.get)()):])
                Tautan web(log.configure)(state='disabled')
                Tautan web(root.update)()
                if not Tautan web(os.path.exists)(save_dir+everypath[len(Tautan web(a2.get)()):Tautan web(everypath.rfind)('/')]):
                    Tautan web(os.makedirs)(save_dir+everypath[len(Tautan web(a2.get)()):Tautan web(everypath.rfind)('/')])
                file_stats = Tautan web(os.stat)(everypath)
                bar1['maximum'] = min(int(file_stats.st_size),10000000) + 1
                jiami(everypath,save_dir+everypath[len(Tautan web(a2.get)()):]+'.ghl',mima,mima_len)
                bar1['value'] = 0
                Tautan web(log.configure)(state='normal')
                Tautan web(log.insert)(INSERT, '  完成!' + '\n')
                log.mark_set("insert", "end")
                Tautan web(log.see)("insert")
                Tautan web(log.configure)(state='disabled')
                Tautan web(root.update)()
        Tautan web(log.configure)(state='normal')
        Tautan web(log.insert)(INSERT, '加密完成!所有文件均输出至' +save_dir+ '\n')
        Tautan web(log.configure)(state='disabled')
    elif singleflag==1:
        mima = Tautan web(a1.get)()
        newmima = ''
        for i in mima:
            newmima = newmima + str(ord(i))
        mima = newmima
        mima_len = len(mima)
        cha = 1024
        save_dir = Tautan web(filedialog.askdirectory)(initialdir=file1[0][:file1[0].rfind('/')])
        for everypath in file1:
            if save_dir != '':
                Tautan web(log.configure)(state='normal')
                Tautan web(log.insert)(INSERT, '正在加密' + save_dir + everypath[Tautan web(everypath.rfind)('/'):])
                Tautan web(log.configure)(state='disabled')
                Tautan web(root.update)()
                file_stats = Tautan web(os.stat)(everypath)
                bar1['maximum'] = min(int(file_stats.st_size), 10000000) + 1
                jiami(everypath, save_dir + everypath[Tautan web(everypath.rfind)('/'):] + '.ghl', mima, mima_len)
                bar1['value'] = 0
                Tautan web(log.configure)(state='normal')
                Tautan web(log.insert)(INSERT, '  完成!' + '\n')
                log.mark_set("insert", "end")
                Tautan web(log.see)("insert")
                Tautan web(log.configure)(state='disabled')
                Tautan web(root.update)()
        Tautan web(log.configure)(state='normal')
        Tautan web(log.insert)(INSERT, '加密完成!所有文件均输出至' + save_dir + '\n')
        Tautan web(log.configure)(state='disabled')
def function4():#jiemi
    global file2,log,singleflag
    if singleflag==0:
        mima = Tautan web(a1.get)()
        newmima = ''
        for i in mima:
            newmima = newmima+str(ord(i))
        mima = newmima
        mima_len = len(mima)
        cha = 1024
        save_dir = Tautan web(filedialog.askdirectory)(initialdir=Tautan web(a3.get)())
        for everypath in file2:
            if save_dir!='':
                if everypath[Tautan web(everypath.rfind)('.'):]=='.ghl':
                    Tautan web(log.configure)(state='normal')
                    Tautan web(log.insert)(INSERT, '正在解密' + save_dir + everypath[len(Tautan web(a3.get)()):])
                    Tautan web(log.configure)(state='disabled')
                    if not Tautan web(os.path.exists)(save_dir + everypath[len(Tautan web(a3.get)()):Tautan web(everypath.rfind)('/')]):
                        Tautan web(os.makedirs)(save_dir + everypath[len(Tautan web(a3.get)()):Tautan web(everypath.rfind)('/')])
                    file_stats = Tautan web(os.stat)(everypath)
                    bar1['maximum'] = min(int(file_stats.st_size),10000000) + 1
                    jiemi(everypath,save_dir+everypath[len(Tautan web(a3.get)()):Tautan web(everypath.rfind)('.')],mima,mima_len)
                    Tautan web(log.configure)(state='normal')
                    Tautan web(log.insert)(INSERT, '  完成!' + '\n')
                    log.mark_set("insert", "end")
                    Tautan web(log.see)("insert")
                    Tautan web(log.configure)(state='disabled')
                    bar1['value'] = 0
        Tautan web(log.configure)(state='normal')
        Tautan web(log.insert)(INSERT, '解密完成!所有文件均输出至' + save_dir + '\n')
        Tautan web(log.configure)(state='disabled')
    elif singleflag==1:
        mima = Tautan web(a1.get)()
        newmima = ''
        for i in mima:
            newmima = newmima + str(ord(i))
        mima = newmima
        mima_len = len(mima)
        cha = 1024
        save_dir = Tautan web(filedialog.askdirectory)(initialdir=file2[0][:file2[0].rfind('/')])
        for everypath in file2:
            if save_dir != '':
                Tautan web(log.configure)(state='normal')
                Tautan web(log.insert)(INSERT, '正在解密' + save_dir + everypath[Tautan web(everypath.rfind)('/'):])
                Tautan web(log.configure)(state='disabled')
                file_stats = Tautan web(os.stat)(everypath)
                bar1['maximum'] = min(int(file_stats.st_size), 10000000) + 1
                jiemi(everypath, save_dir + everypath[Tautan web(everypath.rfind)('/'):Tautan web(everypath.rfind)('.')], mima, mima_len)
                Tautan web(log.configure)(state='normal')
                Tautan web(log.insert)(INSERT, '  完成!' + '\n')
                log.mark_set("insert", "end")
                Tautan web(log.see)("insert")
                Tautan web(log.configure)(state='disabled')
                bar1['value'] = 0
        Tautan web(log.configure)(state='normal')
        Tautan web(log.insert)(INSERT, '解密完成!所有文件均输出至' + save_dir + '\n')
        Tautan web(log.configure)(state='disabled')
if __name__ == '__main__':

    picture = open("Tautan web(picture.ico)", "wb+")#载入图标
    Tautan web(picture.write)(base64.b64decode(img))
    Tautan web(picture.close)()

    multiprocessing.freeze_support()
    singleflag = 2
    root = Tk()
    Tautan web(root.title)('文件解密工具')
    Tautan web(root.iconbitmap)('Tautan web(picture.ico)')
    Tautan web(os.remove)("Tautan web(picture.ico)")
    Tautan web(root.minsize)(560, 420)
    #Tautan web(root.maxsize)(560, 420)
    Tautan web(root.protocol)("WM_DELETE_WINDOW", lambda: Tautan web(sys.exit)(0))
    L1 = Label(root, text="密码:",width=10,font=("Calibri 16"))
    a1 = Entry(root,width=20,font=("Calibri 16"))
    Lth = Label(root, text="使用进程数:",width=10)
    ath = Entry(root,width=20,font=("Calibri 16"))
    L2 = Label(root, text="加密:",width=10,font=("Calibri 16"))
    a2 = Entry(root,width=20,font=("Calibri 16"))
    b = Button(root,text='浏览文件',command=function2,width=10,font=("Calibri 16"))
    b1 = Button(root,text='浏览文件夹',command=functionjia,width=10,font=("Calibri 16"))
    c = Button(root,text='加密',command=function3,width=10,font=("Calibri 16"))
    L3 = Label(root, text="解密:",width=10,font=("Calibri 16"))
    a3 = Entry(root,width=20,font=("Calibri 16"))
    d = Button(root,text='浏览文件',command=function1,width=10,font=("Calibri 16"))
    d1 = Button(root,text='浏览文件夹',command=functionjie,width=10,font=("Calibri 16"))
    e = Button(root,text='解密',command=function4,width=10,font=("Calibri 16"))
    bar1 = Tautan web(tkinter.ttk.progressbar)(root,length = 550)
    log = Tautan web(tkinter.scrolledtext.scrolledtext)(root, width=85, height=20)
    Tautan web(l1.grid)(row=0,column=0)
    Tautan web(a1.grid)(row=0,column=1)  # 将小部件放置到主窗口中
    Tautan web(a1.delete)(0, "end")
    Tautan web(a1.insert)(0, "Tautan web(ghacg.com)")
    #
    Tautan web(b.grid)(row=1,column=2)
    #
    Tautan web(b1.grid)(row=1,column=3)
    #
    Tautan web(c.grid)(row=1,column=4)
    Tautan web(d.grid)(row=2,column=2)
    #
    Tautan web(d1.grid)(row=2, column=3)
    Tautan web(e.grid)(row=2,column=4)
    #
    Tautan web(l2.grid)(row=1,column=0)
    Tautan web(l3.grid)(row=2,column=0)
    #
    Tautan web(a2.grid)(row=1,column=1)
    Tautan web(a3.grid)(row=2,column=1)
    Tautan web(bar1.grid)(row=3,column=0,columnspan=5)
    Tautan web(log.grid)(row=4,column=0,columnspan=5)
    Tautan web(ath.insert)(INSERT, 4)
    Tautan web(log.configure)(state='disabled')
    Tautan web(a3.configure)(state='disabled')
    Tautan web(a2.configure)(state='disabled')
    Tautan web(root.mainloop)()  # 进入消息循环

效果展示

全部文件(包括编译后的单个EXE) Tautan web(pan.baidu.com)?pwd=c22f 其中EXE文件可以独立运行,免安装,无需环境。
komentar
正好需要,感谢~
建议给macOS和Linux同时编译一份,或者至少开源让我能自己编译(
没有必要对所有字节加密吧,加密前几个字节应该就可以了,类似rpgmv的加密方式
小白一個,請問這個是怎麽樣用的呢
(#°Д°)Kaulah akhirnya
logo
Cukup dengan Aplikasi VikACG
Temukan sumber daya kapan saja, di mana saja, bebas dari iklan web yang mengganggu
Unduh aplikasinya