Info

This question is closed. Reopen it to edit or answer.

please explain following encoding code at certain places where comment is present ?

1 view (last 30 days)
function success = encode(msg,key)
num2add = 1000-length(msg);
if num2add < 0, error('This message is too long to encode.'), end
newmsg = [msg,repmat(' ',1,num2add)];% whats happening here pls tell?
msgmat = dec2bin(newmsg)-48;
[filen, pth]=uigetfile({'*.bmp';'*.tif';'*.jpg';'*.png'},'Choose Image To Encode.');
if isequal(filen,0) || isequal(pth,0)
success = []; return % User cancelled.
end
pic1 = imread([pth filen]);
B = pic1(:,:,1); [piclngth, pichght] = size(B);
dim1 = piclngth-2; dim2 = pichght-3; %why have we decreased 2 and 3 in dim ?
keyb = key(end:-1:1);
rows = cumsum(double(key));
columns = cumsum(double(keyb));
A = zeros(dim1,dim2);
A = crtmtrx(A,rows,columns,dim1,dim2,key);
idx = find(A==1);
% please explain below for loop
for vv = 1:1000
for uu = 1:7
if msgmat(vv,uu)==1;
if rem(B(idx(uu+7*(vv-1))),2)==0
B(idx(uu+7*(vv-1))) = B(idx(uu+7*(vv-1)))+1;
end
elseif rem(B(idx(uu+7*(vv-1))),2)==1
B(idx(uu+7*(vv-1))) = B(idx(uu+7*(vv-1)))-1;
end
end
end

Answers (1)

Walter Roberson
Walter Roberson on 20 Mar 2014
We don't know. There are an infinite number of different ways to encode something, and they can be completely arbitrary. The answer is just "Because the author chose to do it that way".
If the author had intended to implement some well-studied encoding mechanism, the author would have documented it in the comments. In the absence of author comments, any routine that does not always crash must be assumed to have been coded exactly the way the author wanted.

Tags

Community Treasure Hunt

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

Start Hunting!