%{
clc;
original = 'Original message for homework';
PosCount = 0;
NegCount = 0;
for i = 1:100
    encrVec = randperm(length(original));
    encoded = original(encrVec);
    decVec = 1:length(original);
    DecMat = [encrVec' decVec'];
    DecMat = sortrows(DecMat);
    decVec = DecMat(:,2);
    decoded = encoded(decVec);
    correct = strcmp(original,decoded);
    if correct == 1
         PosCount = PosCount + 1;
    else
         NegCount = NegCount + 1;
    end
end
disp(['Original: ',original]);
disp(['Encoded: ',encoded]);
disp(['Decoded: ',decoded]);
if PosCount > 98
    disp(['Correct decoding (',num2str(PosCount),' true, ',num2str(NegCount),' false out of 100 try)'])
else
    disp(['Incorrect decoding (',num2str(PosCount),' true, ',num2str(NegCount),' false out of 100 try)']);
end
%}
original='This is my top secret message!';
v=randperm(length(original));
encoded=original(v);
temp=[v',(1:1:length(original))'];
temp2=sortrows(temp);
decoding=temp2(:,2);
decoded=encoded(decoding);
correct=strcmp(original, decoded);
disp(['Original: ', original])
disp(['Encoded : ', encoded])
disp(['Decoded : ', decoded])
disp(['Decoded correctly (1 true, 0 false): ',num2str(correct)])