图像加密基于matlab GUI+Logistic+Tent+Kent+Henon图像加密与解密含Matlab源码 1745期

Posted 紫极神光

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图像加密基于matlab GUI+Logistic+Tent+Kent+Henon图像加密与解密含Matlab源码 1745期相关的知识,希望对你有一定的参考价值。

一、混沌系统简介

0 引言
随着通讯技术的飞速发展, 越来越多的领域需要传送数字图像信号, 因此信息的传送安全问题显得越来越重要。通常应用于数字图像通信的两种保护技术为:数字水印技术和图像加密技术。前一种保护技术因不改变图像的可见性而不适合用于保密图像的传送。后一种技术通过加密操作, 改变图像的可见性, 使原来的图像成为不可辨别的, 而只能通过相应的解密算法得到原始图像。随着通讯技术的发展, 图像加密技术因其具有良好的保密性而得到越来越广泛的应用。
在加密算法中需要一个随机序列发生器。由于离散的混沌系统容易实现, 同时混沌系统对参数和初始条件极其敏感, 把其作为密钥, 则系统具有优良的密码特性, 同时它在二维相平面内的不规则性使其更适用于图像加密。
本文应用离散混沌动力系统, 针对图像数据的存储特点, 设计了一种图像加密算法。所有的密钥都由离散混沌映射产生, 因此算法没有因为增加密钥设置而影响加密/解密的效率和速度。由于利用了混沌映射, 增加了破译难度, 提高了安全性, 仿真结果表明该算法能够有效地实现对数字图像数的加密/解密。

1 混沌系统
混沌现象是一种有界的内在的随机过程, 具有时间遍历性, 这种过程既非周期性, 又不收敛任意相近的两点经过若干次混沌迭代之后, 都会呈现指数发散, 所以很难预测混沌系统的初值和参数。另外, 混沌轨道极其不规则, 系统输出类似于随机噪声, 这些特点均使混沌映射很适用于设计密码系统。

Lyapunov指数是判断系统处于混沌状态的重要判据。Lyapunov指数小于零时, 系统运动状态稳定, 对初始条件不敏感;Lyapunov指数大于零时, 系统状态不稳定, 且对初始条件敏感;Lyapunov指数为零则对应于一种临界状态。由于系统最大Lyapunov指数决定系统的主要演化趋势, 因此可以时间序列的最大Lyapunov指数是否大于零来判断系统是否处于混沌状态。

以简单的一维离散混沌系统Logistic为例, 其动力学系统为:

其中, μ为控制参数。混沌状态如图1所示。
由图可知, 在 3<μ<3.5699456之间, 系统处于周期状态, 当 3.5699456<μ<4时, 系统开始进入混沌状态。
针对Logistic混沌系统, 这里提出一种一维逐段线性混沌系统 (pwlcm) , 其动力学方程为:

其中, x∈I=[0, 1) , p∈ (0, 1/2) , p为控制参数, F是一个在L-bit有限精度下实现的逐段线性混沌映射。其混沌状态如图2所示。

图2 Pwlcm混沌状态图

图3 序列量化性能比较

图4 加密算法流程图
由图所示, (a) 表示Pwlcm的线性分段关系; (b) 是混沌序列图, 说明Pwlcm动力系统是一个混沌的动力学系统; © 、 (d) 分别是其周期倍增分叉与Lyapunov指数谱, 可知Pwlcm系统在控制参数p的整个取值范围内Lyapunov均大于零, 与Logistic系统相比具有更大的密钥取值空间, 同时由图 (b) 可知, Pwlcm系统具有均匀的不变分布与很高的遍历性, 混合性和确定性, 因此可产生很强的随机序列, 适合用于加密系统。

2 混沌量化
对于Pwlcm动力学系统, 采用以下方式进行序列量化, 以产生计算机标准二进制的0-1序列流 Sm (t) 。

其中m>0为任意正整数, Im0, Im1, Im2…是区间[0, 1]的2m个连续的等分区间。由于混沌序列x (t) 具有良好的随机统计特性[3,4], 这样生成的Sm(t)在理论上具有均衡的0-1比和δ-like的自相关等优良的统计特性。其量化结果如图3所示。
图3中,
(a) 表示0-1序列流的自相关函数, 可见其表现了δ-like的自相关特性, 说明该混沌系统在一定的计算精度下的非周期性。
(b) 表示初值相差0.00000015的两个序列流的互相关函数。由图可知, 经量化后的序列流具有很强的随机性, 在初值相差很小的情况下, 其序列流是完全不相关的, 也充分表现了其初值敏感性。
© 表示量化后序列0-1值的个数比。可见系统在经过若干次迭代进入混沌状态后, 其比值近似为1, 充分说明了其混沌系统的遍历性。
(d) 表示随机序列的线性复杂度。

从密码学的观点看, 序列的线性复杂度曲线是表征序列不可预测性和随机性的一个非常有效的度量指标, 对于n位随机序列的线性复杂度期望约等于n/2, 则说明其随机性能良好。这里采用B-M综合算法, 假设混沌二值序列为标准的m序列, 计算得到该序列阶数最小的线性移位寄存器的阶数, 即为该混沌序列的线性复杂度。由图可知, 该混沌序列的随机性能良好, 可满足系统加密要求。
4 图像加密

基于上述的特点, 采用Pwlcm系统应用于图像加密算法。将待加密的图像数据转换为二进制数据, 与量化后的混沌二值序列进行逐位异或计算, 使混沌信号与加密信息信号相互缠绕, 掩盖信息的可视性, 以达到保密的目的。

解密过程与此一致, 解密方采用相同的初值及控制参数, 生成相同的混沌序列, 与接收的加密信号进行逐位异或, 将结果输出还原, 以得到原始信息信号。具体加密过程如图4所示。

虽然Pwlcm系统具有它独特的优势, 但可以发现针对固定的控制参数p很容易被破解。如图2 (a) 所示, 对于 (2) 式迭代生成的混沌序列, 只要得到位于同一分段上的任意两个点对 (x (t) , x (t+1) ) 和 (x (t′) , x (t′+1) ) , 就可以确定参数p= (x (t′) -x (t) ) / (x (t′+1) -x (t+1) ) 。

为了避免参数p被攻破, 可以改变一般对于流密码加密一次一密钥的方式, 采用加密过程中定时更换控制参数p的方法, 以增强抗攻击的能力。

图5 加密解密仿真
这里把所有的密钥都由离散混沌映射产生, 系统由随机函数rand () 产生初值x, 根据x的量化值及p的取值空间来选取p, 假设参数p的分辨率L=10, p的可能的不同值为 p1, p2, p3, …, pn, n=2L, p的选取顺序依x量化值的顺序。算法仿真结果如图5所示。

整个加密过程中, 将初值的量化结果根据控制参数p的取值范围进行转化, 其结果作为p的值进行混沌过程的迭代。本文考虑到读取原始数据进行二进制转换过程中, 单个数值转为8位二进制字符, 图像矩阵最后变为n×8的矩阵, 因此将混沌序列每产生n个值进行一次p值改变。

由仿真结果 (b) 可知, 经加密后的图像信息已完全被打乱, 达到保密效果, 由 © 图可知, 正确的密钥经解密过程, 加密信息可被完全重构, 效果良好。由 (d) 图可知, 即使在初值相差10-17的情况之下, 也不能将加密数据重构出来, 说明其抗攻击性强。

二、部分源代码

function varargout = ChaosEncrypt(varargin)
% CHAOSENCRYPT MATLAB code for ChaosEncrypt.fig
%      CHAOSENCRYPT, by itself, creates a new CHAOSENCRYPT or raises the existing
%      singleton*.
%
%      H = CHAOSENCRYPT returns the handle to a new CHAOSENCRYPT or the handle to
%      the existing singleton*.
%
%      CHAOSENCRYPT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CHAOSENCRYPT.M with the given input arguments.
%
%      CHAOSENCRYPT('Property','Value',...) creates a new CHAOSENCRYPT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ChaosEncrypt_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ChaosEncrypt_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help ChaosEncrypt

% Last Modified by GUIDE v2.5 25-Feb-2022 23:21:04

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ChaosEncrypt_OpeningFcn, ...
                   'gui_OutputFcn',  @ChaosEncrypt_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin1)
    gui_State.gui_Callback = str2func(varargin1);
end

if nargout
    [varargout1:nargout] = gui_mainfcn(gui_State, varargin:);
else
    gui_mainfcn(gui_State, varargin:);
end
% End initialization code - DO NOT EDIT


% --- Executes just before ChaosEncrypt is made visible.
function ChaosEncrypt_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to ChaosEncrypt (see VARARGIN)

% Choose default command line output for ChaosEncrypt
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes ChaosEncrypt wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = ChaosEncrypt_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout1 = handles.output;


% --- Executes on selection change in popupmenu5.
function popupmenu5_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu5 contents as cell array
%        contentsget(hObject,'Value') returns selected item from popupmenu5


% --- Executes during object creation, after setting all properties.
function popupmenu5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popupmenu6.
function popupmenu6_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu6 contents as cell array
%        contentsget(hObject,'Value') returns selected item from popupmenu6


% --- Executes during object creation, after setting all properties.
function popupmenu6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function scramble_num_edit_Callback(hObject, eventdata, handles)
% hObject    handle to scramble_num_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of scramble_num_edit as text
%        str2double(get(hObject,'String')) returns contents of scramble_num_edit as a double


% --- Executes during object creation, after setting all properties.
function scramble_num_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to scramble_num_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Valtrans_num_edit_Callback(hObject, eventdata, handles)
% hObject    handle to Valtrans_num_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Valtrans_num_edit as text
%        str2double(get(hObject,'String')) returns contents of Valtrans_num_edit as a double


% --- Executes during object creation, after setting all properties.
function Valtrans_num_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Valtrans_num_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function SecretKey_edit_Callback(hObject, eventdata, handles)
% hObject    handle to SecretKey_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of SecretKey_edit as text
%        str2double(get(hObject,'String')) returns contents of SecretKey_edit as a double


% --- Executes during object creation, after setting all properties.
function SecretKey_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to SecretKey_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


三、运行结果






四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.

以上是关于图像加密基于matlab GUI+Logistic+Tent+Kent+Henon图像加密与解密含Matlab源码 1745期的主要内容,如果未能解决你的问题,请参考以下文章

图像加密基于混沌系统的图像加密解密matlab源码含GUI

图像加密基于matlab logistic混沌图像加密与解密含Matlab源码 1216期

图像加密基于matlab Logistic混沌+Arnold置乱图像加密含Matlab源码 1281期

图像加密基于matlab DNA混沌系统图像加密含Matlab源码 1190期

图像加密基于matlab DNA混沌系统图像加密含Matlab源码 1190期

MATLAB教程案例29基于Baker映射和Logistic混沌序列的图像加解密matlab实现