三、方案实现 1. 加密过程 介绍:加密按钮EnButtom回调函数 function EnButtonPushed(app, event)
if strcmp('',app.Plaintext.Value)
logRefresh_func_En(app,'请输入明文信息')
return
end
if (app.Row.Value==0)||(app.Colum.Value==0)
logRefresh_func_En(app,'请初始化明文矩阵大小')
return
end
app.Length=length(app.Plaintext.Value);
%将明文存储在对应的矩阵中
fbar = waitbar(0,'明文载入中,请稍后');
pause(0.5);
app.plaintext=app.Plaintext.Value;
for i=1:app.row
for j=1:app.colum
if (i-1)*app.colum+j<=length(app.plaintext)
app.PlainMat{i,j}=app.plaintext((i-1)*app.colum+j);
else
app.PlainMat{i,j}=' ';
end
end
waitbar(i/app.row,fbar,'明文矩阵生成中');
pause(0.07);
end
waitbar(1,fbar,'明文矩阵生成完成');
logRefresh_func_En(app,'明文矩阵生成完成')
pause(0.5);
%对明文矩阵进行加密处理得到ciphertext
for n=1:app.colum
for m=1:app.row
if ((n-1)*app.row+m)==1
app.ciphertext=app.PlainMat{m,n};
else
app.ciphertext=[app.ciphertext,app.PlainMat{m,n}];
end
end
waitbar(n/app.colum,fbar,'密文生成中');
pause(0.07);
end
waitbar(1,fbar,'加密成功');
logRefresh_func_En(app,'加密成功')
app.Crypt.Value=app.ciphertext;
app.Crypt_De.Value=app.ciphertext;
pause(0.5);
close(fbar)
end
2. 解密过程 介绍:解密按钮DeButtom回调函数 function DeButtonPushed(app, event)
high=ceil(app.Length/app.colum_De);
%将密文存储在对应的矩阵中
fbar=waitbar(0,'密文载入中,请稍后');
pause(0.5);
for i=1:app.colum_De
for j=1:app.row_De
if(i-1)*app.row_De+j<=length(app.ciphertext)
app.CipherMat{j,i}=app.ciphertext((i-1)*app.row_De+j);
else
app.CipherMat{j,i}='';
end
end
waitbar(i/app.row_De,fbar,'密文矩阵生成中');
pause(0.07);
end
waitbar(1,fbar,'密文矩阵生成完成');
logRefresh_func_De(app,'密文矩阵生成完成')
pause(0.5);
%对密文矩阵进行加密处理得到plaintext
forn=1:high
form=1:app.colum_De
if((n-1)*app.colum_De+m)==1
app.plain=app.CipherMat{n,m};
else
app.plain=[app.plain,app.CipherMat{n,m}];
end
end
waitbar(n/app.colum_De,fbar,'明文生成中');
pause(0.07);
end
app.Plaintext_De.Value=app.plain;
waitbar(1,fbar,'解密成功');
logRefresh_func_De(app,'解密成功')
pause(0.5);
close(fbar)
end
3. 信息输出 介绍:加密界面信息输出函数logRefresh_func_En function logRefresh_func_En(app,StrArrayNew)
app.Ptime=datestr(now);
app.LOG=strcat('[',app.Ptime(end-7:end),']');
StrArrayNew=strcat(app.LOG,StrArrayNew);
app.StrArray_En=[app.StrArray_En,StrArrayNew,newline];
app.Process_En.Value=app.StrArray_En;
end
介绍:解密界面信息输出函数logRefresh_func_De function logRefresh_func_De(app,StrArrayNew)
app.Ptime=datestr(now);
app.LOG=strcat('[',app.Ptime(end-7:end),']');
StrArrayNew=strcat(app.LOG,StrArrayNew);
app.StrArray_De=[app.StrArray_De,StrArrayNew,newline];
app.Process_De.Value=app.StrArray_De;
end
4. 交互界面 Matlab2019b的mlapp开发环境
|