📄 rsa_enc.asv
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This program applies (RSA) %
% Developed by Hiba Al-younes %
% 5th Year, Computer Engineering Department, University of Damascus %
% Information and Network Security Material %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function RSA_ENC()
format long
%generate primary parameters (p & q)
maple('z1:=',randint(1,1,[12 20]));
p=maple('nextprime(z1)');
p=str2double(p);
maple('z2:=',randint(1,1,[22 30]));
q=maple('nextprime(z2)');
q=str2double(q);
%compute n=p*q.
n=p*q;
maple('n1:=',n);
% opening the file being ciphered
f=fopen('message.txt');
[msg,count]=fread(f);
fclose(f);
%compute olar function .
Qn=olar(n);
maple('Qn1:=',Qn);
%compute general key .
maple('z3:=',randint(1,1,30));
e=maple('nextprime(z3)');
e=str2double(e);
while(gcd(Qn,e)~=1)
maple('z3:=',randint(1,1,30));
e=maple('nextprime(z3)');
e=str2double(e);
end
maple('e1:=',e);
%%%%%%%%%%%%%%%%%%%%%%%
% Compute Cipher text %
%%%%%%%%%%%%%%%%%%%%%%%
Ciphertext=[];
for i=1:1:count
maple('msg1:=',msg(i));
c=maple('(msg1) &^(e1) mod (n1)');
c=str2double(c);
Ciphertext = [Ciphertext c];
end
save('RSA','Ciphertext','n','e');
f=fopen('cipher message.txt','w');
cn=fwrite(f,Ciphertext);
fclose(f);
open 'cipher message.txt';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -