1 Star 0 Fork 1

王其/托管

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
xor加密.py 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
王其 提交于 2021-10-26 07:46 +08:00 . rename xor加密 to xor加密.py.
#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
#随机生成一个32位的十六进制,0~F,作为一次性key
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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wang-qi3206/trusteeship.git
git@gitee.com:wang-qi3206/trusteeship.git
wang-qi3206
trusteeship
托管
master

搜索帮助