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