%  This function converts an input text string (text) into an output 
%  binary vector of numbers (bin).  Each letter will be encoded into 6
%  binary bits.

function [bin] = binaryencode(text);

text_length = length(text);
binary_output='';
character='';
code_matrix= [];

for i= 1:text_length,
   character= text(i);
   switch character
		case {' '}, code_matrix = [0 0 0 0 0 0];
		case {'0'}, code_matrix = [0 0 0 0 0 1];
		case {'1'}, code_matrix = [0 0 0 0 1 0];
		case {'2'}, code_matrix = [0 0 0 0 1 1];
		case {'3'}, code_matrix = [0 0 0 1 0 0];
		case {'4'}, code_matrix = [0 0 0 1 0 1];
		case {'5'}, code_matrix = [0 0 0 1 1 0];
		case {'6'}, code_matrix = [0 0 0 1 1 1];
		case {'7'}, code_matrix = [0 0 1 0 0 0];
		case {'8'}, code_matrix = [0 0 1 0 0 1];
		case {'9'}, code_matrix = [0 0 1 0 1 0];
		case {'.'}, code_matrix = [0 0 1 0 1 1];
		case {','}, code_matrix = [0 0 1 1 0 0];
		case {'!'}, code_matrix = [0 0 1 1 0 1];
		case {'?'}, code_matrix = [0 0 1 1 1 0];
		case {'"'}, code_matrix = [0 0 1 1 1 1];
		case {':'}, code_matrix = [0 1 0 0 0 0];
		case {';'}, code_matrix = [0 1 0 0 0 1];
		case {'#'}, code_matrix = [0 1 0 0 1 0];
		case {'%'}, code_matrix = [0 1 0 0 1 1];
		case {'*'}, code_matrix = [0 1 0 1 0 0];
		case {'+'}, code_matrix = [0 1 0 1 0 1];
		case {'='}, code_matrix = [0 1 0 1 1 0];
		case {'/'}, code_matrix = [0 1 0 1 1 1];
		case {'\'}, code_matrix = [0 1 1 0 0 0];
		case {'-'}, code_matrix = [0 1 1 0 0 1];
		case {'_'}, code_matrix = [0 1 1 0 1 0];
		case {'@'}, code_matrix = [0 1 1 0 1 1];
		case {'$'}, code_matrix = [0 1 1 1 0 0];
		case {'('}, code_matrix = [0 1 1 1 0 1];
		case {')'}, code_matrix = [0 1 1 1 1 0];
		case {'{'}, code_matrix = [0 1 1 1 1 1];
		case {'}'}, code_matrix = [1 0 0 0 0 0];
		case {'~'}, code_matrix = [1 0 0 0 0 1];
		case {'^'}, code_matrix = [1 0 0 0 1 0];
		case {'<'}, code_matrix = [1 0 0 0 1 1];
		case {'>'}, code_matrix = [1 0 0 1 0 0];
		case {'&'}, code_matrix = [1 0 0 1 0 1];
		case {'a'}, code_matrix = [1 0 0 1 1 0];
		case {'b'}, code_matrix = [1 0 0 1 1 1];
		case {'c'}, code_matrix = [1 0 1 0 0 0];
		case {'d'}, code_matrix = [1 0 1 0 0 1];
		case {'e'}, code_matrix = [1 0 1 0 1 0];
		case {'f'}, code_matrix = [1 0 1 0 1 1];
		case {'g'}, code_matrix = [1 0 1 1 0 0];
		case {'h'}, code_matrix = [1 0 1 1 0 1];
		case {'i'}, code_matrix = [1 0 1 1 1 0];
		case {'j'}, code_matrix = [1 0 1 1 1 1];
		case {'k'}, code_matrix = [1 1 0 0 0 0];
		case {'l'}, code_matrix = [1 1 0 0 0 1];
		case {'m'}, code_matrix = [1 1 0 0 1 0];
		case {'n'}, code_matrix = [1 1 0 0 1 1];
		case {'o'}, code_matrix = [1 1 0 1 0 0];
		case {'p'}, code_matrix = [1 1 0 1 0 1];
		case {'q'}, code_matrix = [1 1 0 1 1 0];
		case {'r'}, code_matrix = [1 1 0 1 1 1];
		case {'s'}, code_matrix = [1 1 1 0 0 0];
		case {'t'}, code_matrix = [1 1 1 0 0 1];	
		case {'u'}, code_matrix = [1 1 1 0 1 0];
		case {'v'}, code_matrix = [1 1 1 0 1 1];
		case {'w'}, code_matrix = [1 1 1 1 0 0];
		case {'x'}, code_matrix = [1 1 1 1 0 1];
		case {'y'}, code_matrix = [1 1 1 1 1 0];
		case {'z'}, code_matrix = [1 1 1 1 1 1];
	end

binary_output= [binary_output code_matrix];

end

bin= binary_output;
