XOR加密

可以将最后两行的key改为key1,输入Hello World就能验证参考中的例子

文件在云班课中

代码如下:

import random
import hashlib

def XOR(x,y):
ciphertext=''
for i in x:
a=''
m=bin(int(i,16))[2:]
n=bin(int(y[x.index(i)],16))[2:]
x=x[1:]
y=y[1:]
while len(m)< 4:
m='0'+m
while len(n)< 4:
n='0'+n
for i in m:
if i==n[0]:
i='0'
a=a+i
m=m[1:]
n=n[1:]
else:
i='1'
a=a+i
m=m[1:]
n=n[1:]
b=int(a,2)
c=hex(b)[2:]
ciphertext=ciphertext+c
return ciphertext

text=input('Please input your text:')
m=hashlib.md5()
m.update(text.encode(encoding='utf-8'))
md5=m.hexdigest()
print('MD5:'+md5)

key=''
while len(key)<32:
suijishu = hex(random.randint(0x0, 0xF))
suijishu1 = suijishu[2:]
key=key+suijishu1

key1='5f26cf3906a1f8dcda62707931b6af8a'

print('Key:'+key)
print('CipherText:'+XOR(md5,key))


 

 

 

 

 

 

 

posted on 2020-10-27 21:57  20201323谭顺心  阅读(198)  评论(0)    收藏  举报