AstroCryptV1.0.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:AstroCrypt 作者: Faizaankhan3 项目源码 文件源码
def encrypt(key , filename):
    chunksize = 64 * 1024
    outputFile = filename+".enc"
    filesize = str(os.path.getsize(filename)).zfill(16)
    IV = ''

    for i in range(16):
        IV += chr(random.randint(0, 0xFF))

    encryptor = AES.new(key, AES.MODE_CBC, IV)

    with open(filename, 'rb') as infile:
        with open(outputFile, 'wb') as outfile:
            outfile.write(filesize)
            outfile.write(IV)

            while True:
                chunk = infile.read(chunksize)

                if len(chunk) == 0:
                    break
                elif len(chunk) % 16 != 0:
                    chunk += ' ' * (16 - (len(chunk) % 16))

                outfile.write(encryptor.encrypt(chunk))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号