Score:0

How can I decode a XOR cipher with a string key I know?

cn flag

I have a text that has been XORed with the key "77U" (I am sure of this as it is a file created by a code I have, so I have seen every entry getting XORed by 77U.

However, none of the online decryptors I have tried are giving me any valuable results (error, or something gibberish), some don't have the option to put a string as a key so I tried converting it to ASCII but I still don't get any good results.

For trial purposes, that is part of the file I want to decrypt:

D>9,?9m=(#)$#*Gb|ub}mw|zwm

Some characters are being altered by the website so here is a screenshot:

enter image description here

Any help would be appreciated!

ck flag
This is referenced in [a meta question](https://meta.stackexchange.com/questions/376440/broken-feed-for-the-cryptography-site).
ck flag
Is the listed part of the file supposed to be valid printable characters or is it essentially binary data? Or [UTF-16](https://en.wikipedia.org/wiki/UTF-16) where UTF-8 is expected?
Score:0
cn flag
vnd

Welcome unno!

You can use Python to define decryption function:

def decrypt(encrypted: bytes, key: bytes):
    result = []
    
    for i in range(len(encrypted)):
        result.append(encrypted[i] ^ key[i % len(key)])

    return bytes(result)

In this case I believe the text was encrypted with a single character of decimal ASCII code 77 (letter M):

% python3 -i xor.py
>>> encrypted = b"D>9,?9m=(#)$#*Gb|ub}mw|zwm"
>>> key = bytes([77, ])
>>> decrypt(encrypted, key)
b'\tstart pending\n/18/0 :17: '

Other online decoders should work as well once you specify 'M' (or 0x4D in hexadecimal representation) as a key.

unno avatar
cn flag
What about the U? Why did you just take 77 instead of 77U?
unno avatar
cn flag
Moreover, when I pasted the 3 lines in the uploaded screenshot I got ""Syntax Error: cannot mix bytes and nonbytes literals""
unno avatar
cn flag
for reference, here is the full file: https://pastebin.com/baFm7EqC
cn flag
vnd
You probably get SyntaxError because text has quotation marks inside and you paste it without escaping. You need to escape it first, load from file or use triple-quotes like this: >>> b"""text " is " here"""
cn flag
vnd
Regarding U, it often stands for Unicode. As for values <128 Unicode is same as ASCII, I've just tried 77 as a decimal value and it seemed like the text deciphered with this key was something meaningful.
unno avatar
cn flag
any idea how can I load it entirely from the file as I am having trouble pasting it since it is really big and I am getting "The text contains control characters, which could allow the pasted content to perform arbitrary commands. To confirm and Paste, you can use ⇧⌘⏎."
unno avatar
cn flag
so it might be ruining some parts.
cn flag
vnd
Try: >>> encrypted = open("file.txt", "rb").read()
unno avatar
cn flag
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/134293/discussion-between-unno-and-vnd).
unno avatar
cn flag
thank you so much this is working!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.