Python中使用密钥的RC4解密

Python中使用密钥的RC4解密,python,encryption,passphrase,rc4-cipher,Python,Encryption,Passphrase,Rc4 Cipher,我从这里提取了asp的代码,然后通过base64运行 我想知道是否有人能帮我弄清楚如何用Python编写解密程序。因为解密将发生在我的Python服务器页面上 找到此链接,但它不会从第一个链接解密RC4 asp -吉姆 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ASP页面 Python服务器页面 def decode64(in_str): import base64 decodedStr = base64.b64

我从这里提取了asp的代码,然后通过base64运行

我想知道是否有人能帮我弄清楚如何用Python编写解密程序。因为解密将发生在我的Python服务器页面上

找到此链接,但它不会从第一个链接解密RC4 asp

-吉姆

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ASP页面

Python服务器页面

 def decode64(in_str):
    import base64
     decodedStr = base64.b64decode(in_str)
 return decodedStr

def rc4crypt(data, key):
    x = 0
    box = range(256)
    for i in range(256):
        x = (x + box[i] + ord(key[i % len(key)])) % 256
        box[i], box[x] = box[x], box[i]
    x,y = 0, 0
    out = []
    for char in data:
        x = (x + 1) % 256
        y = (y + box[x]) % 256
        box[x], box[y] = box[y], box[x]
        out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256]))
    return ''.join(out)
 decStr = rc4crypt(decode64(encStr), "1234")

无法理解为什么python decrypt在使用相同的密钥“1234”

将“python rc4”输入到您喜爱的搜索引擎时不呈现原始字符串。我的工作正是你需要的。如果您需要base64代码,请在下一步中输入“python base64”。我找到的所有内容都是用于加密…我需要解密..我不认为RC4是单向散列,对吗?RC4的加密和解密操作是相同的。RC4生成一个伪随机字节流,并将数据与之异或。所以这是它自己的反面。(事实上,我给你的链接解释了这一点。)好吧,也许ASP/VBscript加密部分不起作用……或者你没有使用完全相同的密钥。(例如,您可能在一种情况下使用ASCII键,在另一种情况下使用十六进制键。或者您可能在一种情况下包括终止零字节,而不是另一种。依此类推。)
 def decode64(in_str):
    import base64
     decodedStr = base64.b64decode(in_str)
 return decodedStr

def rc4crypt(data, key):
    x = 0
    box = range(256)
    for i in range(256):
        x = (x + box[i] + ord(key[i % len(key)])) % 256
        box[i], box[x] = box[x], box[i]
    x,y = 0, 0
    out = []
    for char in data:
        x = (x + 1) % 256
        y = (y + box[x]) % 256
        box[x], box[y] = box[y], box[x]
        out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256]))
    return ''.join(out)
 decStr = rc4crypt(decode64(encStr), "1234")