1

我正在尝试为公众制作我的程序(免费软件),我只想知道用于加密文件的代码。(Python 语言 2.7.3)

4

2 回答 2

3

这里有你需要的

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()        

您是否尝试过在 google 上搜索它,甚至是 stackoverflow。

于 2012-10-06T04:41:54.533 回答
3

查看PyCrypto

您还可以搜索本机 python 实现,但它们的效率会降低。

于 2012-10-06T05:37:24.627 回答