如何制作一个python脚本来加密任何类型的fi

2024-05-18 08:44:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力使我的程序为公众(免费软件),我只想知道使文件加密的代码。(Python语言2.7.3)


Tags: 文件代码程序语言免费软件公众
2条回答

给你需要的东西

def encoder(path,pwd,topath):
    """
    @path: file path you wish to encrypt including filename
    @pwd: seek value 'you should remember that if you want to decrypt it'
    @topath: file path for encrypted file included filename
    """
    k = long(pwd) # key   # password in int
    f1 = open( path, "rb") # file path you wish to encrypt
    bytearr = map (ord, f1.read() ) 
    f1.close()
    f2 = open( topath, "wb" ) # path for encrypt file to write
    random.seed(k)
    for i in range(len(bytearr)):
        byt = (bytearr[i] + random.randint(0, 255)) % 256
        f2.write(chr(byt))
    f2.close()        

你有没有试过在谷歌上搜索它,甚至是stackoverflow。在

退房PyCrypto

您也可以搜索本机python实现,但是效率会降低。在

相关问题 更多 >