【信号加密】基于递归水印(RWM)算法实现硬实时信号加密附matlab代码

文章提出了递归水印(RWM)算法,用于保障工业控制系统中硬实时通道的数据完整性。由于现有加密算法无法满足此类系统的速度需求,RWM通过水印噪声在发射端和接收端使用相同的密钥进行信号处理,从而能检测并防止延迟或数据注入攻击。通过代码示例展示了算法如何在信号中嵌入水印以及在遭受攻击时恢复信号的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法       神经网络预测       雷达通信       无线传感器        电力系统

信号处理              图像处理               路径规划       元胞自动机        无人机 

⛄ 内容介绍

网络安全对工业控制系统(ICS)至关重要,如船舶自动化、制造、建筑和能源自动化系统。许多控制应用需要硬实时通道,其延迟和抖动在几毫秒或更少的水平。据我们所知,没有一种加密算法对于现有的工业现场总线的硬实时通道来说足够快,因此,使关键任务的应用容易受到网络攻击,如延迟和数据注入攻击。在这篇文章中,我们提出了一种新型的递归水印(RWM)算法,用于硬实时控制系统数据完整性验证。使用水印密钥,发射器将水印噪声应用于硬实时信号,并通过未加密的硬实时通道发送。同样的密钥通过加密的非实时信道传输给接收器。通过相同的密钥,接收器可以检测到数据是否被攻击者修改,并采取行动防止灾难性的破坏。我们提供分析和方法来设计适当的水印密钥以确保可靠的攻击检测。

⛄ 部分代码

%%

% Real time water mark signal prototype

% Zhen Song

% Parameter

Len=1000

Seed=123

mu=0.2

Nq=1024 % quantiation level

N0=1

% Nc=50 % reset every 50 cycles

% Attack Parameters prototype

AttTime = 400;

AttType = 'delay'; 

% AttType = 'inject';

rng(Seed) % pseudo rand

Hf=rand(Len,1);

% Hashing Dictionary

HashR=rand(Len,1);

%% Original signal

t=linspace(1,5*pi,Len)';

% Simple

%S=sin(t); 

% More demanding

S=sin(t)+cos(2*t) + [2*ones(Len/2,1); transpose(linspace(2,-2,Len/4)) ;-2*ones(Len/4,1)];

Vsf=S+mu*Hf; %V = S+Hf*mu

Vsfr=zeros(length(S),1);

Vsfr(1)=S(1);

% Vsfr(2:end)=Vsf(2:end)+mu*HashPM1(Vsf(1:end-1), HashR); % scaling factor

% must be the same!

%  %V = S+Hf*mu+Hr*mu

for idx=2:Len

    Vsfr(idx)=S(idx)+mu*Hf(idx)+mu*HashPM1(Vsfr(idx-1), HashR) - mu;

end

%% Recovery without attack

Shat=zeros(length(Vsfr),1);

% Reset point

Shat(1)=Vsfr(1);

for idx=2:Len

    Shat(idx)=Vsfr(idx)-mu*Hf(idx)-mu*HashPM1(Vsfr(idx-1), HashR)+mu;

end

Sdiff=Shat-S;

%% Man in the midle attack

% Injection attack

AttInjection = Vsfr + [0*ones(AttTime,1); transpose(linspace(0,5,Len/4)) ; 5*ones(Len-Len/4-AttTime,1)]; 

% Time delay (Replay) attack

AttDelay = [Vsfr(1:AttTime); Vsfr(AttTime); Vsfr(AttTime+1:end-1)];

% Choose the attack

if strcmp(AttType, 'delay')

    Vhack1=AttDelay; 

elseif strcmp(AttType, 'inject')

    Vhack1=AttInjection; 

else

    Vhack1= Vsfr;

end

%% Recovery with attack

Shat_hack1=zeros(length(Vhack1),1);

% Reset point

Shat_hack1(1)=Vhack1(1);

for idx=2:Len

    Shat_hack1(idx)=Vhack1(idx)-mu*Hf(idx)-mu*HashPM1(Vhack1(idx-1), HashR) + mu;

end

Sdiff_hack1=Shat_hack1-S;

%% Chi^2 square test calculation

chi2test=[0];

% Chi square test

clear Y Y_attack n 

for idx=2:Len

    chi2test(idx)=chi_2(Shat_hack1(idx),Shat_hack1(idx-1));

end

    

%% Displaying results

close all;

subplot(3,2,1)

plot(S);

hold on;

plot(Vsfr, 'k');

% legend('S', 'S+Hf', 'S+Hf+Hr');

legend('S', 'V')

title('With Water Mark');

subplot(3,2,2)

plot(Vsfr);

hold on;

plot(Vhack1, '-.r');

plot([AttTime AttTime],[1.3*min([Vsfr; Vhack1]) 1.3*max([Vsfr; Vhack1])],'k--')

legend('V', 'V hack');

title(strcat('Attack at t=',num2str(AttTime)));

subplot(3,2,3)

% recover

plot(S);

hold on;

plot(Shat,'-.r');

legend('S', 'S hat');

title('Recovered signal.');

% subplot(3,2,4)

% % plot(abs(fft(Shat)));

% plot(abs(fft(diff(Shat))));

% title('FFT(diff (S hat) )')

subplot(3,2,4)

% plot(abs(fft(Shat)));

hold on

plot(chi2test);

plot([AttTime AttTime],[0 1.2*max(chi2test)],'k--')

title('Chi^{2} test')

legend('Chi^{2} test');

subplot(3,2,5)

h1=plot(S);

hold on;

h2=plot(Shat_hack1, 'r');

legend([h1, h2], 'S', 'S hat hack1');

plot([AttTime AttTime],[1.3*min([Shat_hack1; S]) 1.3*max([Shat_hack1; S])],'k--')

title(strcat('Attack at t=',num2str(AttTime)));

subplot(3,2,6)

% plot(abs(fft(Shat_hack1)));

hold on

h1=plot(abs(fft(diff(Shat_hack1))));

h2=plot(abs(fft(diff(Shat))));

legend([h1,h2],'S', 'hacked');

title('FFT(diff(S hat hack1))')

% Correction with Hf

A=[Hf S];

disp('Raw data')

cor=corrcoef(A)

A0=[Hf Vsfr];

disp('Noise')

cor0=corrcoef(A0)

A1=[Hf Shat];

A2=[Hf Shat_hack1];

disp('No attack')

cor1=corrcoef(A1)

disp('With delay attack')

cor2=corrcoef(A2)

function y = HashPM1_old(in, hash_dict)

% in is a column vector [-1, 1]

dict_len=length(hash_dict);

y = zeros(size(in));

%     for idx =1:length(in)

if max(in) > min(in)

    idx_dict = round((in-min(in))/(max(in)-min(in))*dict_len);

else

    idx_dict = round((in-1.5)/(2.5)*dict_len);

end

idx0 = find(idx_dict<=0);

idx_dict(idx0)=1;

idx1 = find(idx_dict>=dict_len);

idx_dict(idx1)=dict_len;

y = hash_dict(idx_dict);

%     end

end

%% Simplified Hashing function

% The upper one did not work properly so I created this simplified one, I

% did not want to touch your code :)

function y = HashPM1(in, hash_dict)

% dictionary length

dict_len=length(hash_dict);

y = zeros(size(in));

% Simple index search 

% Signal bounded on [-10,10]

idx_dict = mod(round((in+10)/20 * dict_len),dict_len)+1;

y = hash_dict(idx_dict);

end

%% Chi^2 test function

function [gk_chi] = chi_2(y,y_attack) 

persistent Y Y_attack n 

% time-window length

window =50;

% variance of the noise - amplification

Variance = 10e-3;

if isempty(Y)

    n = 0;

    Y = zeros(window,1);

    Y_attack = zeros(window,1);

else

    if(n > 2)

        % simple system dynamics compensation

        dY = Y(1)-Y(2);

        %dY = 0;

    else

        dY = 0;

    end

    % Buffering signal

    Y = [y; Y(1:end-1)];

    Y_attack = [y_attack+dY; Y_attack(1:end-1)];

    n=n+1;

end

% test calculation

gk_chi = sum((Y-Y_attack).*Variance^-1.*(Y-Y_attack));

end

⛄ 运行结果

⛄ 参考文献

[1] 孙爱娟. 基于AES加密算法的改进及其MATLAB实现[D]. 哈尔滨理工大学, 2010.

[2] 刘昭勇, 代安定, 李康,等. 基于复合混沌系统的彩色图像加密算法及Matlab实现[J]. 湖南城市学院学报(自然科学版), 2018.

[3] 张晓峰, 贾晓强. 一种基于数字音频信号的加密算法[J]. 电子设计工程, 2018, 26(14):5.

⛳️ 代码获取关注我

❤️部分理论引用网络文献,若有侵权联系博主删除

❤️ 关注我领取海量matlab电子书和数学建模资料

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值