1

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.

anon
  • 23
  • 5
  • There is no such thing as a Julia cipher and your code doesn't make sense to decode anything, you're not using the key. Even with all that, coding solutions to cipher challenges is off topic here. – Marc Sep 14 '20 at 16:59
  • If the question is about python, it is off-topic here, see our [help section](https://crypto.stackexchange.com/help/on-topic). If the question is about how to break this cipher, hint: gzip files are [well-documented](https://tools.ietf.org/html/rfc1952), that gives you some amount of known plaintext, perhaps enough to recover the key without guesswork. @Marc: I can see at least an attempt to use the key, by XORing it (repeated) with the ciphertext, then performing a byte right-rotate by one bit. Discussion about the pitfalls of that code are off-topic. – fgrieu Sep 14 '20 at 17:01
  • 3
    @anon: people here can help (now that it's on SO), but you need to know the cipher used or show a working example of decryption using the key. Your code as is cannot decode anything, it's just mangling the ciphertext and writing it back to a file (a much much bigger file). – Marc Sep 14 '20 at 17:15
  • @Marc: you are totally right, I hallucinated that `eb` was used where there is `ch0` on the next line. – fgrieu Sep 14 '20 at 17:34
  • 1
    @anon I think the point of the exercise is that you analyse the crypt text and come up with a strategy yourself. For example, given that it is likely a gzipped file: do you know of any particular constants (e.g. file headers) that seem to be rotated a particular fixed amount? – user268396 Sep 14 '20 at 18:34
  • You have an encrypted .gz file. Look at the known parts of the .gz file format: fixed headers, file length etc. that will give you a partial plaintext which will in turn give you an insight into parts of the encryption. Work back from the parts you can work out. If it is a substitution cipher then you can use any substitutions you find to help elsewhere in the file. – rossum Sep 14 '20 at 20:29
  • @user268396 thanks for responding, I will consider this as I continue working through the problem. – anon Sep 15 '20 at 06:41
  • @rossum thanks for also responding, I think I have a better understanding of the problem now. – anon Sep 15 '20 at 06:41

0 Answers0