Program: Cipher Text
Program: Cipher Text
clc; clear all; close all; for x=1:3; p=input('Enter Plain Text: ','s'); p=double(p); k=input('Enter key:'); k=mod(k,26); c=(p+k); for i=1:length(c) if p(i)>=65&&p(i)<=90 if c(i)>90 c(i)=65+mod(c(i),90)-1; end else if p(i)>=97&&p(i)<=122 if c(i)>122 c(i)=97+mod(c(i),122)-1; end end end end disp('The encrypted o/p is:'); disp(char(c)) o=(c-k); for j=1:length(c) if c(j)>=65&&c(j)<=90 if o(j)<65 o(j)=90-mod(65,o(j))+1; end else if c(j)>=97&&c(j)<=122 if o(j)<97 o(j)=122-mod(97,o(j))+1; end end end end disp('The decrypted o/p is:') disp (char(o)) end
OUTPUT:
Enter Plain Text: thakur college of engineering Enter key:36 The encrypted o/p is: drkueb*myvvoqo*yp*oxqsxoobsxq The decrypted o/p is: thakur college of engineering Enter Plain Text: THAKUR COLLEGE OF ENGINEERING Enter key:63 The encrypted o/p is: ESLVFC+NZWWPRP+ZQ+PYRTYPPCTYR+ The decrypted o/p is: THAKUR COLLEGE OF ENGINEERING Enter Plain Text: THAKUR COLLEGE of Engineering Enter key:5 The encrypted o/p is: YMFPZW%HTQQJLJ%tk%Jslnsjjwnsl The decrypted o/p is: THAKUR COLLEGE of Engineering