I need help with encryption, spaces are giving me a hard time. More details in the body of post

1 view (last 30 days)
yes I've been bugging the threads with my questions a lot but hopefully this should be the last time. so my goal is to turn a message into numbers, then turn the encoded message (that are now numbers) back into letters again.
here is the code that I've used to get the letters into numbers:
clc, clear
message= 'hello how are you'
s_s = message;
index = 0;
encryption = zeros(1,length(s_s));
for s_ss = 1: length(s_s)
index = index + 1;
encryption(index) = (double(s_s(index)) - 96 )
end
and here is the code to switch the numbers back into vectors:
C = 'abcdefghijklmnopqrstuvwxyz1234567890 ';
V = input('enter message here');
v=V;
x=C(v)
I have them separate as for now. The problem however is in the first code, it makes spaces equal to -64. That will not work with the second code to turn it back into letters. I have to keep basic substitution such as a=1 b=2 ect ect and that first code does that but its the spaces that are giving me the problem. Any help would be very appreciated.
This is for an online class, the criteria will be attached.

Answers (1)

Walter Roberson
Walter Roberson on 4 Aug 2015
' ' does not have a char() of at least 96, so when you subtract 96 you get a negative value.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!