내가 Crypto와 파이썬에서이 blog (헤더 아래 응용 프로그램)에서 3DES 암호화를 사용하고, 그리고 내가 Tree of Fun Files에서 테스트했습니다의 암호 해독없는 부분, 이 질문은 많은 다른 파일 중에서 An Accountant and his Frog.txt입니다 (파일 크기는 크게 달라집니다, 예 : TOASTERS).Pyocrypt DES3 파일 암호화, 텍스트
pyencrypt
import os
from Crypto.Cipher import DES3
def encrypt_file(in_filename, out_filename, chunk_size, key, iv):
des3 = DES3.new(key, DES3.MODE_CFB, iv)
with open(in_filename, 'r') as in_file:
with open(out_filename, 'w') as out_file:
while True:
chunk = in_file.read(chunk_size)
if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += ' ' * (16 - len(chunk) % 16)
out_file.write(des3.encrypt(chunk))
def decrypt_file(in_filename, out_filename, chunk_size, key, iv):
des3 = DES3.new(key, DES3.MODE_CFB, iv)
with open(in_filename, 'r') as in_file:
with open(out_filename, 'w') as out_file:
while True:
chunk = in_file.read(chunk_size)
if len(chunk) == 0:
break
out_file.write(des3.decrypt(chunk))
사용
import pyencrypt, md5
from Crypto import Random
iv = Random.get_random_bytes(8)
m = md5.new()
m.update("encryptionkey")
key = m.digest()
.encrypt_file("C:\\treeoffunfiles\\Accountant and his frog.txt", 'C:\\treeoffun\\to_enc.enc', 8192, key, iv)
pyencrypt.decrypt_file('C:\\treeoffunfiles\\to_enc.enc', 'C:\\treeoffunfiles\\to_enc.dec', 8192, key, iv)
그리고 파일의 암호화가 크다 (불만이)! 그러나 파일의 decryption은 그렇게 크지는 않습니다. 다음은 원래 파일과 해독 된 파일 간의 comparison 출력을 notepad++에서 가져온 것입니다.
notepad++ http://iforce.co.nz/i/3qnyhvzf.b5w.png
해독 된 파일은 원본의 내용을없는 이유가 뭘까요? 그리고 암호 해독 (및 필요한 경우 암호화)을 더 정확하게 (파일 크기가 다를 수 있음) 만들 수 있습니까?
8192는 무엇에 관한 것입니까? 16384를 사용하면 어떻게됩니까? – eactor
지금까지 내가 볼 수있는 Chunk_size는 파이썬의 읽기 전용으로 사용 되었기 때문에 입력에서 8192 바이트를 읽었습니까? 더 긴 입력 파일이 있으면 어떻게됩니까? – eactor
'16384'의 결과는 [this] (http://www.diffnow.com/?report=g94bz) _better_와 같지만 시가는 여전히 없습니다. – Killrawr