How to implement RSA encryption in simulink

6 views (last 30 days)
Hello! I wany to create a bloc in Simulink with Embedded Function block. I have done a code witch works perfetly but just code in matlab. i'm trying to put it into the Embedded Function block but it shows a lot of errors. here is the code:
%%Private Key
p=53;
q=97;
%%Public Key
n=p*q;
d=4151;
e=179;
%%Entrée
m=input('\nEnter the message: ','s');
m1=m-0;
over=length(m1);
o=1;
while(o<=over);
m=m1(o)-32;
qm=dec2bin(e);
len=length(qm);
c=1;
xz=1;
while(xz<=len)
if(qm(xz)=='1')
c=mod(mod((c^2),n)*m,n);
elseif(qm(xz)=='0')
c=(mod(c^2,n));
end
xz=xz+1;
end
%%Results stored in a vector
y(o)=c;
o=o+1;
end

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!