windows 加密隐私文件方式

有时候移动硬盘存点小电影,老怕别人借过去发现。所以要加密一下

用隐藏文件的方式。加上对文件后缀名的加密

用一个脚本,输入密码输入正确才可以自动显示文件。

主要用cmd的 attrib 命令

两个比较重要的参数 h 和s 

隐藏时cmd命令为 attrib +h +s 文件

显示时cmd命令为 attrib -h -s 文件

python脚本代码如下

# -*- coding: utf-8 -*-
import os


class test():
    def __init__(self,filename):
        self.filename = filename
    #视频文件后缀加密
    def encrypt(self):
        for root,dirs,files in os.walk(self.filename, topdown=False):
            for file in files:
                #print(os.path.join(root, file))
                name = file.split('.',1)
                #print name[1]


                if name[1] == 'mp4':
                    #os.chdir(root)
                    newname = str(name[0])+".liao"
                    os.rename(os.path.join(root, file),os.path.join(root, newname))
                elif name[1] == 'avi':
                    #os.chdir(root)
                    newname = str(name[0])+".liao1"
                    os.rename(os.path.join(root, file),os.path.join(root, newname))
                elif name[1] == 'rmvb':
                    #os.chdir(root)
                    newname = str(name[0])+".liao2"
                    os.rename(os.path.join(root, file),os.path.join(root, newname))
                else:
                    pass
                    
    #视频文件后缀解密
    def decrypt(self):
        for root,dirs,files in os.walk(self.filename, topdown=False):
            for file in files:
                print(os.path.join(root, file))
                name = file.split('.',1)
                print name[1]


                if name[1] == 'liao':
                    #os.chdir(root)
                    newname = str(name[0])+".mp4"
                    os.rename(os.path.join(root, file),os.path.join(root, newname))
                elif name[1] == 'liao1':
                    #os.chdir(root)
                    newname = str(name[0])+".avi"
                    os.rename(os.path.join(root, file),os.path.join(root, newname))
                elif name[1] == 'liao2':
                    #os.chdir(root)
                    newname = str(name[0])+".rmvb"
                    os.rename(os.path.join(root, file),os.path.join(root, newname))
                else:
                    pass
                    
if __name__ == "__main__":
    filename = 'test'
    #隐藏文件test
    test(filename).encrypt()
    p = os.popen('attrib +s +h' + ' '+ filename)
    p.close()


    #输入密码显示文件
    password = '123456'


    count = 1 
    max = 3 #设置最大尝试次数
    while True:
        input = raw_input("请输入文件密码:")
        if input != password:
            if (max-count) == 0:
                print "已经超过最大尝试次数"
                break
            else:
                print "密码输入错误%s次,您还有%s次"%(count,max-count)
                count += 1
        else:
            print "密码输入正确正在解锁"
            p = os.popen('attrib -s -h' +' '+ filename)
            p.close()
            test(filename).decrypt()
            print "解锁完成"
            break
 输入密码正确才可以显示文件夹,输入错误3次则会停止程序。

然后再使用pyinstaller 把脚本转换成exe文件。放到目录下就可以了。


pyinstaller 打包很方便。直接pyinstaller -F -c pass.py


打包以后执行界面是这样的


输入密码后就可以解锁成功。然后就会显示出隐藏的文件夹。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值