python 解码rc4的问题

默魑 发布于 2016/12/03 23:02
阅读 242
收藏 0
报错信息如下:

Traceback (most recent call last):
  File "C:\607_java\JAVA_ITEMS\asdf\asdff.py", line 40, in <module>
    encoded_data = tencode(data=data, key=key)  
  File "C:\607_java\JAVA_ITEMS\asdf\asdff.py", line 25, in tencode
    data = salt + crypt(data, sha1(key + salt).digest())  
TypeError: Unicode-objects must be encoded before hashing


求解!!!!!

def tencode(data, key, encode=base64.b64encode, salt_length=16):
        salt = ''  
        for n in range(salt_length):  
            salt += chr(random.randrange(256))  
            
            
        data = salt + crypt(data, sha1(key + salt).digest())  
        if encode:  
            data = encode(data)
        return data  
       
def tdecode(data, key, decode=base64.b64decode, salt_length=16):
        if decode:  
                data = decode(data)  
        salt = data[:salt_length]  
        return crypt(data[salt_length:], sha1(key + salt).digest())  
       
       
if __name__=='__main__':
        data = 'UUyFTj8PCzF6geFn6xgBOYSvVTrbpNU4OF9db9wMcPD1yDbaJw==' 
        key = 'welcometoicqedu'
        encoded_data = tencode(data=data, key=key)  
        print (encoded_data)
        decoded_data = tdecode(data=encoded_data, key=key)  
        print (decoded_data)



加载中
0
大洋的顶端
大洋的顶端
你这不是RC4加密,就是个MD5的salt加密
默魑
不是啊,这只是一部分代码,这个是解rc4的,是别人在i春秋论坛上贴出的解码脚本
返回顶部
顶部