When encrypting a file symmetrically with gpg -c file.txt, when and how does it compress the file?

I was working on a cryptopals challenge and wanted to test out my AES ECB detection function. I made a simple text-file that was around 1KB and encrypted it through the python package PyCrypto, the output file was also 1KB. I took this same file and encrypted it via gpg and got a file that was only 100B. My ECB detection function completely failed to tell it was 128 AES-ECB.

Edit: I've noticed that no matter the file, when the contents are encoded to b64 the first string is always jA0EBwMC, yet even removing these first bytes from the data doesn't yield any repeat blocks.

I tried to decompress the file with bz2, but it put out an error saying it wasn't a bzip2 file. I also can't tell if the file was compressed before the cipher was applied or before. How can you deal with something like this?

  • $\begingroup$ What kind of research have you done? Have you tried looking at the GPG man page? I did for a few seconds, and it answered one of your questions. It probably answers the other, as well. $\endgroup$ – bkjvbx Mar 17 '17 at 10:59
  • $\begingroup$ All I found was an entry on -z. It says the default is to the level of zlip. It doesn't tell me if it's done before or after encryption, and it also doesn't help me "undo" it. I've tried to decompress the file the usual ways, but nothing seems to work. $\endgroup$ – Astrum Mar 17 '17 at 11:14
  • 1
    $\begingroup$ Allegedly, gpg supports zip, zlib and bzip2. Compression is always done before encryption because afterwards you have uncompressable random-looking data. $\endgroup$ – SEJPM Mar 17 '17 at 12:00
  • $\begingroup$ @Astrum You read that the default compression is zlib. So why not try decompressing it as zlib data? E.g. unix.stackexchange.com/questions/22834/… $\endgroup$ – bkjvbx Mar 17 '17 at 12:35
  • $\begingroup$ @Astrum: compression works best before encryption; it does not work on properly encrypted data (unless that's ASCII-armored, and then only at the price of losing that, and within the reduction allowed by the armor, typically -25% at best). $\endgroup$ – fgrieu Mar 17 '17 at 12:36

Browse other questions tagged or ask your own question.