Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Secure communication through cryptography Sending the data from the transmitter

ID: 3572091 • Letter: S

Question

Secure communication through cryptography Sending the data from the transmitter to the receiver through an open and non-secure wireless channel could allow unauthorized individuals to intercept and read the data. You are assigned the task of designing an encryption and decryption functions using either C++ or MATLAB to make sure that even if the data was intercepted by any unauthorized person he will not be able to understand its meaning. The encryption function is described as follows: Get the text to be sent (P) and replace each letter of it with its substitution according to the table below: ABCDEFGHIJKLMNOPQRSTUVWXYZ ZYXWVUTSRQPONMLKJIHGFEDCBA Consider that each letter of the alphabet is assigned a number starting with A=01 and ending at Z=26. Get the numerical representation of each letter generated from the previous step and save it in array. Add K to each element of the created array in the previous step to generate a new array where each element is shifted by k num

Explanation / Answer

Code:

Encrypt.m file

function C=Encrypt(p,k)
atoz = 'abcdefghijklmnopqrstuvwxyz ';
ztoa = 'zyxwvutsrqponmlkjihgfedcba ';
np = '';
l = 1;
%step 1
for j=1:length(p)
for i=1:26
if(p(j) == atoz(i))
np(l) = ztoa(i);
l = l+1;
end
end
end
%step 2
index = [];
for i=1:length(np)
index(i) = strfind(atoz,np(i));
end
%step 3 adding k
k = 2;
index = index+k;
%step 4 array to cell
finalIndex = num2cell(index);
C = '';
for i=1:length(finalIndex)
if(eq(finalIndex{i},1))
C = strcat(C,'01') ;
elseif(eq(finalIndex{i},2))
C = strcat(C,'02') ;
elseif(eq(finalIndex{i},3))
C = strcat(C,'03') ;
elseif(eq(finalIndex{i},4))
C = strcat(C,'04') ;
elseif(eq(finalIndex{i},5))
C = strcat(C,'05') ;
elseif(eq(finalIndex{i},6))
C = strcat(C,'06') ;
elseif(eq(finalIndex{i},7))
C = strcat(C,'07') ;
elseif(eq(finalIndex{i},8))
C = strcat(C,'08') ;
elseif(eq(finalIndex{i},9))
C = strcat(C,'09') ;
else
C = strcat(C,num2str(finalIndex{i})) ;
end
end
end

Decrpyt.m file

function str = Decrypt(C,k)
atoz = 'abcdefghijklmnopqrstuvwxyz';
ztoa = 'zyxwvutsrqponmlkjihgfedcba';
index = [];
for k = 1: 2: length(C)
index = strread(C,'%2s');
end
newIndex = str2double(index);
newIndex1 = [];
for i=1:length(newIndex)
newIndex1(i)=newIndex(i)-2;
end
str = '';
for i=1:length(newIndex1)
str = strcat(str,ztoa(newIndex1(i)));
end
end

test.m file

p = 'howareyou';
p
C = Encrypt(p,2)
str = Decrypt(C,2)

Output:


p =

howareyou


C =

211406281124041408


str =

howareyou

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote