I am reading 64kb from a generated text file "generated.txt" and writing the data to txt files at the beginning of every written txt file there is strange data, except at the first written file.
If i use:
with open('generated.txt', 'rb') as f:
instead of:
f = open('generated.txt', 'rb')
I get the same strange data in the first file.
Beginning of the second 64k block of the orginal file in hex:
0a31303935300d0a31303935310d0a31
"Strange" Data form the second txt file in hex:
e7fadb0930588fb74d1aba3fd3bafc84
Beginning of the second file encryptet in hex:
bde07ad1e305193105655a42998a1fc9
Unfortunately not the same
Full Code below:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from Crypto.Cipher import AES
from Crypto.Protocol.KDF import PBKDF2
from Crypto import Random
key_size = 32
iterations = 10000
key = 'password'
salt = Random.new().read(key_size)
iv = Random.new().read(AES.block_size)
derived_key = PBKDF2(key, salt, key_size, iterations)
cipher = AES.new(derived_key, AES.MODE_CFB, iv)
i = 1
f = open('generated.txt', 'rb')
while True:
data = f.read(65536)
if not data:
break
encodedtext = iv + cipher.encrypt(data)
decodedtext = str(cipher.decrypt(encodedtext))[16:]
print 'Writing ' + str(i)
g = open('LOG_' + str(i) + '.txt', 'wb')
g.write(decodedtext)
g.close()
d = open('LOG_' + str(i) + '_ENC.txt', 'wb')
d.write(encodedtext)
d.close()
i = i+1
f.close()
Thanks for your help :)