How to get the XOR key from a python file?

436 views Asked by At

So, I have this encrypted file. I want the key so I can decrypt it. I don't want it in decrypted form, I want it in encrypted form and know the decryption process, or put into text form. Here is the function for the key:

def encrypt(input_data, password):
    key = 0
    for ch in password:
        key ^= ((2 * ord(ch) + 3) & 0xff)

    return xor(input_data, key)

How do I get the key to appear so I can decrypt it? I want it to print the key to a text file.

1

There are 1 answers

0
TessellatingHeckler On
def encrypt(input_data, password):
    key = 0
    for ch in password:
        key ^= ((2 * ord(ch) + 3) & 0xff)

    with open('key.txt', 'w') as f:
        f.write("{0:b}".format(key).zfill(8))

    return xor(input_data, key)