How to decrypt a .txt.gz.enc file with a python program without knowing the key?

1.5k Views Asked by At

For this problem I have been given an encrypted text file and have been asked to find the key and then decrypt the file into a .txt.gz file.

So far, I know that the cipher I should be using is a type of substitution cipher. I was given the code that was used to encrypt the message and I know that I will need an XOR Rotation in order to find the key and decipher the message.

This is code that I had developed when I was given a key

import sys
import gzip

with open("juliaplaintext.txt.gz.enc", "rb") as f:
    data = f.read()
k = data.decode("utf-8")
i =0
key = "IbSeMGjyepOr" * 10000
rotated = b""

s = open("juliaplaintext.txt.gz", "wb")

for ch0, ch1 in zip(k, key):
    eb = chr(ord(ch0) ^ ord(ch1))
    rotated += bytes(ord(eb) >> 7 & 0xff | ord(eb) << 7)
    s.write(rotated)

s.close()

I am very new to python and am unsure how to go about creating a decoding program when I am not given the key. Any help is very appreciated.

0

There are 0 best solutions below