function [P] = Plain2Cipher(S)
% function [P] = Plain2Cipher(S)
% S is a string input, containing only capital letters and spaces
% P is a 2-by-M matrix of integers between 0 and 25
% P is found after conversion of characters into numbers 

j = 0;
for k = 1 : length(S)
    if (S(k) ~= ' ')
        j = j+1;
        SS(j) = S(k); % trail S and delete all empty spaces
    end
end

% If the string S has (2*M-1) letters, 
% the last pair is filled by an arbitrary "dummy" letter such as "Z".
mS = length(SS);
M = ceil(mS/2);
if (mS ~= 2*M)
    SS(2*M) = 'Z'; % SS has now (2*M) letters
    mS = 2*M;
end
% V is a 2-by-M matrix of characters after breaking S into pairs of characters
V(1,:) = SS(1:2:mS);
V(2,:) = SS(2:2:mS);

P = zeros(2,M);
for i = 1 : 2 
    for j = 1 : M
        switch V(i,j)
        case 'A',
            P(i,j) = 1;
        case 'B',
            P(i,j) = 2;
        case 'C',
            P(i,j) = 3;
        case 'D',
            P(i,j) = 4;
        case 'E',
            P(i,j) = 5;
        case 'F',
            P(i,j) = 6;
        case 'G',
            P(i,j) = 7;
        case 'H',
            P(i,j) = 8;
        case 'I',
            P(i,j) = 9;
        case 'J',
            P(i,j) = 10;
        case 'K',
            P(i,j) = 11;
        case 'L',
            P(i,j) = 12;
        case 'M',
            P(i,j) = 13;
        case 'N',
            P(i,j) = 14;
        case 'O',
            P(i,j) = 15;
        case 'P',
            P(i,j) = 16;
        case 'Q',
            P(i,j) = 17;
        case 'R',
            P(i,j) = 18;
        case 'S',
            P(i,j) = 19;
        case 'T',
            P(i,j) = 20;
        case 'U',
            P(i,j) = 21;
        case 'V',
            P(i,j) = 22;
        case 'W',
            P(i,j) = 23;
        case 'X',
            P(i,j) = 24;
        case 'Y',
            P(i,j) = 25;
        case 'Z',
            P(i,j) = 0;
        end
    end
end

        