xor加密的python实现


#md5加密
import hashlib
hash_md5 = hashlib.md5()
x=input("Please input your text:")
print( "Text:",x)
data = x.encode('utf-8', errors='ignore')
hash_md5.update(data)
md5_str = hash_md5.hexdigest()
print("MD5:",md5_str)


#形成key
from random import *
rad="".join([choice("0123456789ABCDEF") for i in range(32)]) 
print ( "key:", rad)


#xor加密
txt1=[]
t=''
u=''
for a in range(32):
    i='0x'+md5_str[a]
    j='0x'+rad[a]
    p=bin(eval(i)).replace('0b','')
    q=bin(eval(j)).replace('0b','')
    for c in range(min(len(p),len(q))):
        if (p[-c]==q[-c])  :
            e='0'
        elif(p[-c]!=q[-c]):
            e='1'
        t=e+t
    t='0b'+t
    d=t
    t=''    
    s=hex(eval(d)).replace('0x','')
    u=u+s
print("CipherText:",u)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM