資源簡介
用python實現(xiàn)了圖像的混沌加密與解密,是參考某位大佬博客上面的用matlab實現(xiàn)了的加密解密算法
代碼片段和文件信息
from?PIL?import?Image
import?numpy?as?np
import?math
“““
作者:???????RyanChen
創(chuàng)建日期:???2018/10/26
描述:???????python實現(xiàn)圖像的混沌加密
參考:???????https://blog.csdn.net/u013626386/article/details/39736611
?????????????https://blog.csdn.net/hust_bochu_xuchao/article/details/52687755
“““
def?ImageEncrypt(image):
image=np.array(image.convert(‘L‘))
width=image.shape[0]
height=image.shape[1]
A1=np.zeros((width?height)dtype=np.uint8)
A2=np.zeros((width?height)dtype=np.uint8)
u1=4
u2=4
x1=np.zeros(width*height)
x1[0]=0.2
x2=np.zeros(width*height)
x2[0]=0.7
y1=np.zeros(width*height)
y2=np.zeros(width*height)
sumA=sum(sum(image))
k=np.mod(sumA256)*1.0/255
x1[0]=(x1[0]+k)/2
x2[0]=(x2[0]+k)/2
y1[0]=((1/3.1415926)*math.asin(np.sqrt(x1[0])))
y2[0]=((1/3.1415926)*math.asin(np.sqrt(x2[0])))
for?i?in?range(0width*height-1):
x1[i+1]=u1*x1[i]*(1-x1[i])
x2[i+1]=u2*x2[i]*(1-x2[i])
fo
評論
共有 條評論