MATLAB Answers

Write a Matlab program that converts a string (text) message up to 140 characters long into an encrypted message, and then decrypts the message to return the same string. I dont know where I went wrong, any help?

49 views (last 30 days)
Dewayne
Dewayne on 10 Oct 2013
Commented: Maryam AlRabee on 3 Aug 2015
%variables
C='abcdefghijklomnpqrstuvwxyz 1234567890.,!?$%';
%Input
num=0;
while num==0
A=input('input your message to be encrypted, Must be 140 characters or less ','s');
if size(A)<=140;
num=1;
end
end
%display
disp('Your message')
disp(A)
%Encode
for I=0:size(A)
for D=1:size(C)
if A(D)==C(D)
A(I)=D;
break;
end
end
end
E=randi(10,10,140);
E=E*inv(E);
encoded=A*E;
reshape(A,10,140);
%display
disp('Encoded message',encoded)
%Decode
F=inv(E);
decoded=encoded*F;
for J=1:size(decoded)
for(K=1:26)
if decoded(K)==B(K)
decoded(K)=B(K);
break;
end
end
end
disp('Your message has been decoded ',decoded)
  2 Comments
Maryam AlRabee
Maryam AlRabee on 3 Aug 2015
yes! An error that says "Error using reshape To RESHAPE the number of elements must not change.
Error in Encryption (line 26) reshape(A,140,10);"

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!