how can I speed up this function ?

I'm working on a steganography project . i wrote a simple lsb function that hides one letter of a message in one pixel of an image but it's too slow because of the loops and dec2binvec function(according to profile). i need to make it run faster.any help?
function [red,blue,green] = encrypt(red,blue,green,data)
data = dec2binvec(data,8);
%encrypting the blue bits
i = 1;
while( i <=3)
if(data(i) ~= bitget(blue,i))
if(data(i) == 0)
blue = bitset(blue,i,0);
else
blue = bitset(blue,i,1);
end
end
i = i+1;
end
%encrypting the green bits
i = 1;
t=4;
while( i <=3 && t <= 6)
if(data(t) ~= bitget(green,i))
if(data(t) == 0)
green = bitset(green,i,0);
else
green = bitset(green,i,1);
end
end
i = i+1;
t = t+1;
end
%encrypting the red bits
i = 1;
t=7;
while( i <=2 && t <= 8)
if(data(t) ~= bitget(red,i))
if(data(t) == 0)
red = bitset(red,i,0);
else
red = bitset(red,i,1);
end
end
i = i+1;
t = t+1;
end
return;

Answers (0)

Categories

Products

Asked:

on 10 Feb 2016

Edited:

on 11 Feb 2016

Community Treasure Hunt

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

Start Hunting!