I created a encrypted file from a text file in python with beefish.
beefish uses pycrypto.
so my source text file is 33742 bytes and the encrypted version is 33752.
thats ok so far but ...
when I compress the test.enc (encrypted test file) with tar -czvf the final file is 33989 bytes. Why does the compression not work when the source file is encrypted?
So far the only option then seems to compress it first and then encrypt it cause then the file stays that small.
The compression method used by tar -z relies on repeating patterns in the input file, replacing these patterns by a count of how many times the pattern repeated (grossly simplified).
However, when you encrypt a file, you are basically trying to hide any repeating patterns in as much 'random'-looking noise as possible. That makes your file nearly incompressible. Combine that with the overhead of the archive and compression file format (metadata, etc.) and your file actually ends up slightly larger instead.
You should reverse the process; compress first, then encrypt, and you'll increase the chances you end up with a smaller payload significantly.
compressed encrypted file is bigger then source