% embed a binary message into an image file
% allow the user to enter a text string that
% will be converted to binary and embedded into
% the image

imageName = input('name of the image: ');
I = imread(imageName);
figure(1)
image(I)
% remove all zero values in image since we will use 
% zero to denote a one in our binary (put in function)
[a,b] = size(I);
for i=1:a
    for j=1:b
        if I(i,j) == 0
            I(i,j) = 1;
        end
    end
end

message = input('message to embed: ');
message = lower(message);

% preallocate
c = zeros(a,b);

% convert string to binary (put in function)
% set starting row
s = 1;
n = 1;
for k=1:length(message)
    switch message(k)
        case 'a'
            c(s,8*(n-1)+1:8*n) =    [0 1 1 0 0 0 0 1];
            n = n + 1;
        case 'b'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 0 0 1 0];
            n = n + 1;
        case 'c'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 0 0 1 1];
            n = n + 1;
        case 'd'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 0 1 0 0];
            n = n + 1;
        case 'e'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 0 1 0 1];
            n = n + 1;
        case 'f'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 0 1 1 0];
            n = n + 1;
        case 'g'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 0 1 1 1];
            n = n + 1;
        case 'h'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 1 0 0 0];
            n = n + 1;
        case 'i'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 1 0 0 1];
            n = n + 1;
        case 'j'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 1 0 1 0];
            n = n + 1;
        case 'k'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 1 0 1 1];
            n = n + 1;
        case 'l'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 1 1 0 0];
            n = n + 1;
        case 'm'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 1 1 0 1];
            n = n + 1;
        case 'n'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 1 1 1 0];
            n = n + 1;
        case 'o'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 0 1 1 1 1];
            n = n + 1;
        case 'p'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 1 0 0 0 0];
            n = n + 1;
        case 'q'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 1 0 0 0 1];
            n = n + 1;
        case 'r'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 1 0 0 1 0];
            n = n + 1;
        case 's'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 1 0 0 1 1];
            n = n + 1;
        case 't'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 1 0 1 0 0];
            n = n + 1;
        case 'u'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 1 0 1 0 1];
            n = n + 1;
        case 'v'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 1 0 1 1 0];
            n = n + 1;
        case 'w'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 1 0 1 1 1];
            n = n + 1;
        case 'x'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 1 1 0 0 0];
            n = n + 1;
        case 'y'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 1 1 0 0 1];
            n = n + 1;
        case 'z'
            c(s,8*(n-1)+1:8*n) = 	[0 1 1 1 1 0 1 0];
            n = n + 1;
        otherwise
            s = s + 1; % add new word on new row
            n = 1; % start new row in first column
    end
end

% now we can encode the image
for i=1:a
    for j=1:b
        if c(i,j) == 1
            I(i,j) = 60; 
        end
    end
end
figure(2)
image(I)