Eric Y. answered 03/16/14
Tutor
5
(5)
SAT Prep
Caesar Cipher
A Caesar Cipher shifts the alphabet by (x) spaces. If (x) were 1, "HI"
would become "IJ", and "XYZ" would become "YZA". Note that the coded
alphabet will wrap around (Z->A).
Also note that given an encoding (x), the encoded message can be decoded
with (-x).
The following is a script written in MATLAB to encode a message given (x).
It was extremely unnecessary, but fun. The answer is at the bottom.
mymessage = 'LXX MABL UHHD BL WHGX';
%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
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);
would become "IJ", and "XYZ" would become "YZA". Note that the coded
alphabet will wrap around (Z->A).
Also note that given an encoding (x), the encoded message can be decoded
with (-x).
The following is a script written in MATLAB to encode a message given (x).
It was extremely unnecessary, but fun. The answer is at the bottom.
mymessage = 'LXX MABL UHHD BL WHGX';
%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
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);
%End of encoding script
Given the hint, XX must convert to EE or OO.
'X'-'E' = 19
'X'-'O' = 9
When the shifting (x) is -9, the result is...
COO DRSC LYYU SC NYXO
When the shifting (x) is -19, the result is...
SEE THIS BOOK IS DONE
This is your answer.
Eric Y.
Daniel, your math class seems very interesting!
Report
03/17/14
Daniel C.
im taking discrete mathmatics, going to school for software development
Report
03/17/14
Eric Y.
Nice! Then my unnecessary script, may have been partially applicable. I know these questions may seem difficult at first, but once you see the methods a few times, you will catch on. I believe in programming, you will need to look things up a lot(i.e. getting help, looking up examples of how to use other people's code). So, you are doing right in asking questions. Good luck!
Report
03/17/14
Daniel C.
03/16/14