| | |
File size is increased after pickle
Thread Solved |
•
•
Join Date: Sep 2009
Posts: 12
Reputation:
Solved Threads: 0
I'm reading in a file and sending the data (once encrypted) to a dictionary, with a hash of the data before and after encryption. I then pickle the dictionary but find the file size is massive compared to the source file size. If I write the encrypted data straight to a file the size is identical to the source. Any idea why my pickled file is so large?
Python Syntax (Toggle Plain Text)
#Encrypt data and get hashes def encryptAndExportFile(self, key, inFile, outFile): openInFile = open(inFile,"rb") inFileSize = os.path.getsize(inFile) inFileData = openInFile.readlines() openInFile.close() """ initialise cipher """ cipher = AES.new(key, AES.MODE_CFB) """ initialise MD5 """ m = hashlib.md5() #hash h = hashlib.md5() #hash of encrypted dataq encryptedData = [] for data in inFileData: m.update(data) encData = cipher.encrypt(data) h.update(encData) encryptedData.append(encData) hashResult = m.digest() encHashResult = h.digest() return hashResult, encryptedData, encHashResult
Python Syntax (Toggle Plain Text)
def storeEncryptedObject(self, obj, path): outFile = open(path, 'wb') pickle.dump(obj, outFile) outFile.close()
•
•
Join Date: Sep 2009
Posts: 12
Reputation:
Solved Threads: 0
2
#2 24 Days Ago
Using protocol 2 greatly improved file size, which only increases by 5% in some cases.
Python Syntax (Toggle Plain Text)
def storeEncryptedObject(self, obj, path): outFile = open(path, 'wb') pickle.dump(obj, outFile, protocol = 2) outFile.close()
![]() |
Similar Threads
- file size (C++)
- File size in C (Win32) (C)
Other Threads in the Python Forum
- Previous Thread: Removing a substring from string
- Next Thread: Ceasar Cipher
| Thread Tools | Search this Thread |
abrupt accessdenied anti apache application approximation argv array beginner book builtin calculator change converter countpasswordentry curved dan08 dictionaries dictionary dynamic edit enter examples file float format function gui heads homework import inches input java keyboard lapse launcher library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pyopengl python random recursion redirect remote reverse scrolledtext session simple software sprite statictext string strings syntax table terminal text textarea thread threading time tlapse trick tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable wordgame wxpython






