Sunteți pe pagina 1din 2

Shift encryption

clc;
clear all;
close all;
msg=input('enter the message in small letters :','s');
ke = input('Enter key: ');
%encryption
ab = abs(msg);
cd = mod(msg,97)+ke;
op = mod(cd,26);
en = op+97;
en_msg = char(en);
disp('Encrypted msg = ');
disp(en_msg);
%decryption
gg = en - 97;
ef = gg - ke;
gh = mod(ef,26);
hd = gh+97;
de_msg = char(hd);
disp('Decrypted msg = ');
disp(de_msg);

Auto encryption
clc;
clear all;
close all;
%ENCRYPTION
ms=input('enter the mssg','s');
as=abs(ms);%ASCII VALUE
x=as-97;%POSITION VALUE
k=[];
key=input('enter the key');
k(1)=key;
key1=x(1:length(x)-1);
y=[k key1];
z=x+y;%POSITION VALUE
s=mod(z,26);%CRCT POSITION
c=s+97;%ASCII VALUE
cc=char(c);
disp(cc);
%DECRYPTION
aa=abs(cc);
zz=[];
zz=aa-97;
f=[];
for i=2:length(ms)
f(1)=zz(1)-key;
f(i)=zz(i)-f(i-1);
end
sa=mod(f,26);
ss=sa+97;
disp(char(ss));

S-ar putea să vă placă și