base64对称加密

import os
import base64
import hashlib

def zidinyi1(load):
    with open(load) as f:
        content = f.read()
    content1 = content.replace("u", '#')
    content2 = content1.replace("Y", '~')
    f = open(load, 'w')
    f.write(content2)
    f.close()
    print("加密成功")

def jiami(fpath):
    f = open(fpath, encoding='ANSI')
    content = f.read()
    content1 = content.encode('ANSI')
    content2 = base64.b64encode(content1)
    f.close()
    with open(fpath, 'wb+') as f:
        f.write(content2)
    zidinyi1(fpath)

def jiemi(load):
    f = open(load, encoding='ANSI')
    content = f.read()
    content1 = base64.b64decode(content)
    with open(load, 'wb+') as f:
        f.write(content1)
    print('解密成功')

def zidinyi2(load):
    with open(load) as f:
        content = f.read()
    content1 = content.replace("#", 'u')
    content2 = content1.replace("~", 'Y')
    f = open(load, 'w')
    f.write(content2)
    print(type(content2))
    f.close()
    jiemi(load)

def de(fpath):
    print('路径' + fpath)
    if(os.path.exists(fpath)):
        os.remove(fpath)
    else:
        pass

def md (fpath):
    file = open(fpath, 'rb')
    md5 = hashlib.md5(file.read()).hexdigest()
    file.close()
    return md5

def dir(way):
    file = ['txt']
    all_md5 = {}
    try:
        for root, dirs, files in os.walk(way):
            for dirname in dirs:
                dir(dirname)
            for Filename in files:
                path = os.path.join(root, Filename)
                if (Filename[-3:]) in file and Filename[0] != "$":
                    print(path)
                    if md(path) in all_md5.values():
                        # print(path)
                        os.remove(path)
                    else:
                        all_md5[path] = md(path)
                        zidinyi2(path)
                        # jiami(path)
                        # shutil.copy(path, beforedir)
    except FileNotFoundError:
        pass

for i in range(65, 91):
    dirvename = chr(i) + ':'
    if os.path.isdir(dirvename):
        if dirvename != "C:":# and dirvename != "D:"
            print(dirvename)
            dir(dirvename)
# dir(dirvename)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值