Search 75,526 tutors
FIND TUTORS
Ask a question
0 0

Caesar cipher

Tutors, please sign in to answer this question.

2 Answers

MATLAB CODE
 
mymessage = 'VJKU SWKB KU QXGT';
%This is the message to be encoded or decoded by shifting x alphabet units.
x = input('x= ');
%x is the number of alphabet units the message will be shifted by.
%Encoding Script
while x~=99;


   x = mod(x,26);
   for i = 1:size(mymessage,2);
      tempnumber = double(mymessage(1,i));
      if tempnumber == 32;%do not shift spaces
      else
         tempnumber = tempnumber+x;%shift
      end
      if tempnumber>90;%Wrap around
         tempnumber = tempnumber-90+64;
      end
      mymessage(1,i) = char(tempnumber);
   end
   disp(mymessage);
   x = input('x= ');
end
 
 
 
What x's would you attempt?
 
Try x =24, -2...
Note modulus 26, 24 and -2 are the same

Comments

Woodbridge tutors