简体   繁体   English

如何从python文件中获取XOR密钥?

[英]How to get the XOR key from a python file?

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.我希望它将密钥打印到文本文件。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM