复合混沌加密(python版)
复合混沌加密
以下代码使用python实现的复合混沌加密一张图片,该加密算法原理就不讲了,到目前为止破解的人还没出现,先看一看效果图。
图片从左到右分别为原始图像、加密图像、以及解密后的图像,下面为代码。(注意,可加密的图片格式可以为png,bmp,jpg,其它的没有测试,但是可以顺利解密的是png,bmp。jpg格式的图片解密会有不一样的效果,想看的自己可以试一下!)
所用到的库有 opencv、math、numpy
#!/usr/bin/env python
# _*_ coding:utf-8 _*_"""
@Author : AI-Zhang
@Version : V1.0
@E-Mail : 1415984778@qq.com
@File : Cryption.py
@CreateTime : 2021/3/13
@Description : Encryption and Decryption of image
@ModifyTime : 2021/3/13
@company : CSUFT
"""import cv2
import math
import numpy as npdef int2bin8(x): # 整型转8位二进制result="";for i in range(8):y=x&(1)result+=str(y)x=x>>1return result[::-1]def int2bin16(x): # 整型转8位二进制result="";for i in range(16):y=x&(1)result+=str(y)x=x>>1return resultdef Encryption(img,j0,g0,x0,EncryptionImg):x = img.shape[0]y = img.shape[1]c = img.shape[2]g0 = int2bin16(g0)for s in range(x):for n in range(y):for z in range(c):m = int2bin8(img[s][n][z]) # 像素值转八位二进制ans=""print("ok")for i in range(8):ri=int(g0[-1]) # 取手摇密码机最后一位riqi=int(m[i])^ri # 与像素值异或得qixi = 1 - math.sqrt(abs(2 * x0 - 1)) # f1(x)混沌迭代if qi==0: # 如果qi=0,则运用x0i+x1i=1;xi=1-xi;x0=xi # xi迭代t=int(g0[0])^int(g0[12])^int(g0[15]) # 本源多项式x^15+x^3+1g0=str(t)+g0[0:-1] # gi迭代ci=math.floor(xi*(2**j0))%2 # 非线性转换算子ans+=str(ci)re=int(ans,2)EncryptionImg[s][n][z]=re # 写入新图像def Decryption(EncryptionImg, j0, g0, x0, DecryptionImg):x = EncryptionImg.shape[0]y = EncryptionImg.shape[1]c = EncryptionImg.shape[2]g0 = int2bin16(g0)for s in range(x):for n in range(y):for z in range(c):cc = int2bin8(img[s][n][z])ans = ""print("no")for i in range(8):xi = 1 - math.sqrt(abs(2 * x0 - 1))x0 = xissi = math.floor(xi * (2 ** j0)) % 2qi=1-(ssi^int(cc[i]))ri = int(g0[-1])mi=ri^qit = int(g0[0]) ^ int(g0[12]) ^ int(g0[15])g0 = str(t) + g0[0:-1]ans += str(mi)re = int(ans, 2)DecryptionImg[s][n][z] = reif __name__ == "__main__":img = cv2.imread("D:/pycharmproject/network_security/2.bmp", 1) # 读取原始图像cv2.imshow("img", img) # 显示原图EncryptionImg = np.zeros(img.shape, np.uint8)Encryption(img,10,30,0.123345,EncryptionImg) # 加密cv2.imwrite("D:/pycharmproject/network_security/EncryptionImg2.bmp",EncryptionImg) # 保存cv2.imshow("EncryptionImg", EncryptionImg) # 显示img = cv2.imread("D:/pycharmproject/network_security/EncryptionImg2.bmp", 1) # 读取加密图像DecryptionImg = np.zeros(img.shape, np.uint8)Decryption(img, 10, 30, 0.123345, DecryptionImg) # 解密cv2.imwrite("D:/pycharmproject/network_security/DecryptionImg2.bmp", DecryptionImg) # 保存cv2.imshow("DecryptionImg ", DecryptionImg) # 显示cv2.waitKey(0)
复合混沌加密(python版)相关推荐
- 混沌图像加密matlab,基于复合混沌系统的彩色图像加密算法及Matlab实现
第27卷 第3期 湖 南 城 市 学 院 学 报 (自然科学版) Vol. 27 No.3 2018年5月 Journal of Hunan City University (Natural Scie ...
- pyDes 实现 Python 版的 DES 对称加密/解密--转
https://my.oschina.net/leejun2005/blog/586451 手头有个 Java 版的 DES 加密/解密程序,最近想着将其 Python 重构下,方便后续脚本解析,捣鼓 ...
- 算法(Python版)|156Kstars|神级项目-(1)The Algorithms - Python简介
文章目录 算法(Python版) 项目地址 项目概况 说明 参与入门 社区频道 算法列表 Arithmetic Analysis 算术分析 Audio Filters 音频过滤器 Backtracki ...
- json传输二进制的方案(python版)
json传输二进制的方案(python版) 1.json不能直接传二进制文件 json只能传递基本的数型(如:int,long,string等),但不能传递byte类型.但是有时候我们想在json中传 ...
- *** Python版一键安装脚本
本脚本适用环境: 系统支持:CentOS 6,7,Debian,Ubuntu 内存要求:≥128M 日期:2018 年 02 月 07 日 关于本脚本: 一键安装 Python 版 *** 的最新版. ...
- 微信支付SDK(python版)
最近一段时间一直在搞微信平台开发,最近的v3.37版本微信支付接口变化贼大,所以就看着php的demo移植为 python版,为了保持一致,所以接口方法基本都没有变,这样的好处就是不用写demo了,看 ...
- python版亲戚关系计算器
2019独角兽企业重金招聘Python工程师标准>>> 春节到了,免不了要去七大姑八大姨家拜年,顺便接受长辈们的关怀.有时偶然遇到许久没见过的远房亲戚,叫不出合适的称谓就尴尬了:或者 ...
- 【论文摘要】基于多数投票模式和超混沌加密的彩色图像鲁棒安全零水印算法
Robust and secure zero-watermarking algorithm for color images based on majority voting pattern and ...
- python版 —— 验证码校验 打码兔平台的使用介绍
python版 -- 验证码校验 打码兔平台的使用介绍 1. 背景 验证码(CAPTCHA)的全称是全自动区分计算机和人类的图灵测试(Completely Automated Public Turin ...
最新文章
- python自建模块导入_Python模块的使用及自建模块的导入方法举例
- Python3.4 Django MySQL MySQL-python 安装不成功解决办法 Unable to find vcvarsall.bat 错误
- swig封装 c语言函数到python库,python swig 调用C/C++接口
- hihoCoder 1257 Snake Carpet(很简单的构造方法)
- 一份好的工作总结才能帮你升职加薪
- DataGridView常用操作
- 从零搭建自己的SpringBoot后台框架(十三)
- android调节屏幕亮度
- 本地文件上传到阿里云生成网址
- 传奇程序员云风:从创业到被招安,细数我这20年程序人生
- 观远数据完成2.8亿元C轮融资
- 2022年指数与指数公司行业研究报告
- Hacked?软件监控邮箱账号是否存在数据泄露情况
- 如何识别图片中的表格数据
- 2012年上半年信息系统项目管理师 上午试题和参考答案及解析
- Win11安装Ubuntu子系统报错WslRegisterDistribution failed with error: 0x800701bc
- 时间序列分析专题(二)
- ACW830. 单调栈
- mysql计算三角形斜边_下图中,底边和高都是6厘米的等腰三角形,分别以高的长为直径画圆,以底的一半长为直径画两个半圆,求阴影部分...
- linux 纪元时间转换,[转]Linux下时间函数time gettimeofday