Info
This question is closed. Reopen it to edit or answer.
How can I improve this decoder
1 view (last 30 days)
Show older comments
I have to do a decoder for this code, I made one, but the final string (string3) come out with the letters in the order that the encode code gives. What can i do to have the original order of the string? thanks for the help.
%% This is the encode code
function [string1,code]=codificar(string)
b=double(string);
if b(end)<b(1)
[a,c]=sort(b,'descend');
else
[a,c]=sort(b);
end
string1=char(a+1);
code=c;
end
%% And this is what a made
function [string3]=decodificar(string2) % I put string2 and 3 to no confuse with the original string
a=double(string2);
if a(1)<=a(end)
[b,g]=sort(a);
else
[b,g]=sort(a,'descend');
end
string3=char(b-1);
code=g
end
2 Comments
Walter Roberson
on 27 Jun 2019
You cannot return to the original order without knowing the code variable. Consider that bard and brad would have the same output string1, so string1 by itself is not enough information to recover the original string.
Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!