我正在尝试为公众制作我的程序(免费软件),我只想知道加密文件的代码。 (Python语言2.7.3)
答案 0 :(得分: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()
您是否曾尝试搜索谷歌,甚至是stackoverflow。
答案 1 :(得分:3)
查看PyCrypto
您也可以搜索本机python实现,但效率会降低。