0% found this document useful (0 votes)
50 views2 pages

All All 'Enter The Message in Small Letters:' 'S' 'Enter Key: '

This document contains code for performing shift encryption and auto encryption/decryption of messages. The shift encryption code takes a message and key as input, shifts each character by the key, and outputs the encrypted and decrypted messages. The auto encryption code encrypts a message by shifting each character by the sum of all previous keys, and decrypts by shifting characters back in the reverse order of keys.

Uploaded by

sushmetha123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views2 pages

All All 'Enter The Message in Small Letters:' 'S' 'Enter Key: '

This document contains code for performing shift encryption and auto encryption/decryption of messages. The shift encryption code takes a message and key as input, shifts each character by the key, and outputs the encrypted and decrypted messages. The auto encryption code encrypts a message by shifting each character by the sum of all previous keys, and decrypts by shifting characters back in the reverse order of keys.

Uploaded by

sushmetha123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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));

You might also like