XOR加密
作者:互联网
coding=utf-8
md5算法
import hashlib
h_md5 = hashlib.md5()
x = input("输入需要加密的数据:")
print( "Text:",x)
data = x.encode('utf-8', errors='ignore')
h_md5.update(data)
md5_str = h_md5.hexdigest()
print("MD5:",md5_str)
形成key
随机生成十六进制0~F
from random import *
n = "".join([choice("0123456789ABCDEF") for i in range(32)])
print ( "key:", n)
xor运算
txt1 = []
k = ''
u = ''
for a in range(32):
i = '0x' + md5_str[a]
j = '0x' + n[a]
x=bin(eval(i)).replace('0b','')
y=bin(eval(j)).replace('0b','')
for c in range(min(len(x),len(y))):
if (x[-c] == y[-c]) :
e = '0'
elif(x[-c] != y[-c]):
e = '1'
k = e + k
k ='0b' + k
d = k
k = ''
s = hex(eval(d)).replace('0x','')
u = u + s
print("CipherText:",u)
编写过程中参考了同学的。md5算法和随机生成的Key都很好理解,但在最后xor运算上遇到了困难,需要加强学习。
标签:加密,0x,replace,0b,eval,print,XOR,md5 来源: https://www.cnblogs.com/ningxinyu1/p/15472877.html