浏览器运行环境异常,请检查是否开启本站的JavaScript权限或下载最新版浏览器。
Logo
komprehensif
artikel
Komik
bulatan
Trending
tolong
Log masuk
penciptaan
Muat Turun Pantas
Sumber
Pembelajaran
Ruangan
7
Turun
4
mengumpul
Lapor
berkongsi

简单文件加密工具

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

主程序代码:

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

from i import img


def read(dir,address,length,f):
    Pautan Web(f.seek)(address, 0)
    result = Pautan Web(f.read)(length)
    result = b2a_hex(result)
    result = Pautan Web(bytes.decode)(result)
    return result
def write(write_bytes,dir,address,f):
    try:
        write_bytes = bytes().fromhex(write_bytes)
    except:
        print(write_bytes)
    Pautan Web(f.seek)(address, 0)
    result=Pautan 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 = Pautan Web(aes.new)(Pautan Web(secret.encode)('utf-8'), AES.MODE_CBC, iv)
        data = readdata  # 16beishu
        data = bytes().fromhex(data)
        try :
            encrypt_data = Pautan Web(cipher.encrypt)(data)  # 输入需要加密的字符串,注意字符串长度要是16的倍数。16,32,48..
            encrypt_data = Pautan Web(bytes.decode)(b2a_hex(encrypt_data))
            return encrypt_data
        except:
            return Pautan 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 = Pautan Web(aes.new)(Pautan Web(secret.encode)('utf-8'), AES.MODE_CBC, iv)
        try:
            decrypt_data = Pautan Web(cipher.decrypt)(encrypt_data)
            decrypt_data = Pautan Web(bytes.decode)(b2a_hex(decrypt_data))
            return decrypt_data
        except:
            return Pautan Web(bytes.decode)(b2a_hex(encrypt_data))

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

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

    multiprocessing.freeze_support()
    singleflag = 2
    root = Tk()
    Pautan Web(root.title)('文件解密工具')
    Pautan Web(root.iconbitmap)('Pautan Web(picture.ico)')
    Pautan Web(os.remove)("Pautan Web(picture.ico)")
    Pautan Web(root.minsize)(560, 420)
    #Pautan Web(root.maxsize)(560, 420)
    Pautan Web(root.protocol)("WM_DELETE_WINDOW", lambda: Pautan 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 = Pautan Web(tkinter.ttk.progressbar)(root,length = 550)
    log = Pautan Web(tkinter.scrolledtext.scrolledtext)(root, width=85, height=20)
    Pautan Web(l1.grid)(row=0,column=0)
    Pautan Web(a1.grid)(row=0,column=1)  # 将小部件放置到主窗口中
    Pautan Web(a1.delete)(0, "end")
    Pautan Web(a1.insert)(0, "Pautan Web(ghacg.com)")
    #
    Pautan Web(b.grid)(row=1,column=2)
    #
    Pautan Web(b1.grid)(row=1,column=3)
    #
    Pautan Web(c.grid)(row=1,column=4)
    Pautan Web(d.grid)(row=2,column=2)
    #
    Pautan Web(d1.grid)(row=2, column=3)
    Pautan Web(e.grid)(row=2,column=4)
    #
    Pautan Web(l2.grid)(row=1,column=0)
    Pautan Web(l3.grid)(row=2,column=0)
    #
    Pautan Web(a2.grid)(row=1,column=1)
    Pautan Web(a3.grid)(row=2,column=1)
    Pautan Web(bar1.grid)(row=3,column=0,columnspan=5)
    Pautan Web(log.grid)(row=4,column=0,columnspan=5)
    Pautan Web(ath.insert)(INSERT, 4)
    Pautan Web(log.configure)(state='disabled')
    Pautan Web(a3.configure)(state='disabled')
    Pautan Web(a2.configure)(state='disabled')
    Pautan Web(root.mainloop)()  # 进入消息循环

效果展示

全部文件(包括编译后的单个EXE) Pautan Web(pan.baidu.com)?pwd=c22f 其中EXE文件可以独立运行,免安装,无需环境。
Komen
正好需要,感谢~
建议给macOS和Linux同时编译一份,或者至少开源让我能自己编译(
没有必要对所有字节加密吧,加密前几个字节应该就可以了,类似rpgmv的加密方式
小白一個,請問這個是怎麽樣用的呢
(#°Д°)Awak akhir
logo
Cukup sekadar aplikasi VikACG
Cari sumber bila-bila masa, di mana sahaja, tanpa iklan web yang menjengkelkan
Muat turun aplikasinya