Hello I want a deatiled explanation for every step in this code thanks function
ID: 2250041 • Letter: H
Question
Hello I want a deatiled explanation for every step in this code thanksfunction [ En ] = Encryption(x,K)
FWD=['A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z']; REV=['Z' 'Y' 'X' 'W' 'V' 'U' 'T' 'S' 'R' 'Q' 'P' 'O' 'N' 'M' 'L' 'K' 'J' 'I' 'H' 'G' 'F' 'E' 'D' 'C' 'B' 'A']; NUMBER=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26]; kk=1; for xx=1:size(x,2) for yy=1:26 if x(xx)==FWD(yy); inp(kk)=FWD(yy); en(kk)=REV(yy); ennumer(kk)=NUMBER(yy); C(kk)=ennumer(kk)+K; kk=kk+1; break end end end fprintf('The input word is: %s ',inp()) fprintf('The substituion word is: %s ',en()) ennumer() C() L=1; for p=1:size(C,2) for q=1:26 if C(p)==NUMBER(q); decrp(L)=FWD(q-K); end
end decrp() end
>> Encryption('HELLO',5) The input word is: HELLO The substituion word is: SVOOL
ennumer =
8 5 12 12 15
C =
13 10 17 17 20
ans =
H
decrp =
E
decrp =
L
decrp =
L
decrp =
O
>> Hello I want a deatiled explanation for every step in this code thanks
function [ En ] = Encryption(x,K)
FWD=['A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z']; REV=['Z' 'Y' 'X' 'W' 'V' 'U' 'T' 'S' 'R' 'Q' 'P' 'O' 'N' 'M' 'L' 'K' 'J' 'I' 'H' 'G' 'F' 'E' 'D' 'C' 'B' 'A']; NUMBER=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26]; kk=1; for xx=1:size(x,2) for yy=1:26 if x(xx)==FWD(yy); inp(kk)=FWD(yy); en(kk)=REV(yy); ennumer(kk)=NUMBER(yy); C(kk)=ennumer(kk)+K; kk=kk+1; break end end end fprintf('The input word is: %s ',inp()) fprintf('The substituion word is: %s ',en()) ennumer() C() L=1; for p=1:size(C,2) for q=1:26 if C(p)==NUMBER(q); decrp(L)=FWD(q-K); end
end decrp() end
>> Encryption('HELLO',5) The input word is: HELLO The substituion word is: SVOOL
ennumer =
8 5 12 12 15
C =
13 10 17 17 20
ans =
H
decrp =
E
decrp =
L
decrp =
L
decrp =
O
>> Hello I want a deatiled explanation for every step in this code thanks
function [ En ] = Encryption(x,K)
FWD=['A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z']; REV=['Z' 'Y' 'X' 'W' 'V' 'U' 'T' 'S' 'R' 'Q' 'P' 'O' 'N' 'M' 'L' 'K' 'J' 'I' 'H' 'G' 'F' 'E' 'D' 'C' 'B' 'A']; NUMBER=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26]; kk=1; for xx=1:size(x,2) for yy=1:26 if x(xx)==FWD(yy); inp(kk)=FWD(yy); en(kk)=REV(yy); ennumer(kk)=NUMBER(yy); C(kk)=ennumer(kk)+K; kk=kk+1; break end end end fprintf('The input word is: %s ',inp()) fprintf('The substituion word is: %s ',en()) ennumer() C() L=1; for p=1:size(C,2) for q=1:26 if C(p)==NUMBER(q); decrp(L)=FWD(q-K); end
end decrp() end
>> Encryption('HELLO',5) The input word is: HELLO The substituion word is: SVOOL
ennumer =
8 5 12 12 15
C =
13 10 17 17 20
ans =
H
decrp =
E
decrp =
L
decrp =
L
decrp =
O
>>
Explanation / Answer
function [ En ] = Encryption(x,K)
%Alphabets in forward order stroed in FWD array
FWD=['A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z'];
%Alphabets in reverse order stored in REV array
REV=['Z' 'Y' 'X' 'W' 'V' 'U' 'T' 'S' 'R' 'Q' 'P' 'O' 'N' 'M' 'L' 'K' 'J' 'I' 'H' 'G' 'F' 'E' 'D' 'C' 'B' 'A'];
% Numbers 1 to 26 stroed in NUMBER array
NUMBER=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26];
kk=1;
%This for loop length of x times. Size(x) gives 1 by 2 arrow and number of
% rows equal to 1. so here size(x,2) using or we can use length(x)
for xx=1:size(x,2)%xx runnig from 1 to length of xx
for yy=1:26 %yy running from 1 to 26
if x(xx)==FWD(yy);% Comparing input with FWD array
inp(kk)=FWD(yy);% inp() array stores input
en(kk)=REV(yy); % en() array stores input in reverse order equivalent alphabets.
ennumer(kk)=NUMBER(yy); % ennumer() stores input as number
C(kk)=ennumer(kk)+K; %C() stores ennumer + K as array
kk=kk+1;
break
end
end
end
fprintf('The input word is: %s ',inp()); % Printing input
fprintf('The substituion word is: %s ',en()); % Printing en() array
ennumer(); % printing ennumer() [ which input alphabets equivalent numbers]
C(); % Printing C();
%In this for loop deencryption done
L=1;
for p=1:size(C,2)
for q=1:26
if C(p)==NUMBER(q); % If encrypted number equal to number in NUMBER array
decrp(L)=FWD(q-K);% Then decrypted letter
end
end
decrp()% Printing Decrypted Letter
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.