function crypt = mono_encrypt ( code, plain )

%*****************************************************************************80
%
%% MONO_ENCRYPT encrypts a string using a monoalphabetic substitution code.
%
%  Discussion:
%
%    Before the string is encrypted, it is converted to uppercase.
%
%    Only the alphabetic characters A-Z will be encrypted.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    01 October 2016
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, string CODE(26), lists the substitutes for 'A' through 'Z'.
%
%    Input, string PLAIN(*), the string to be encrypted.
%
%    Output, string CRYPT(*), the encrypted version of the string.
%

%
%  How long is the plain text?
%
  n = length ( plain ); 
%
%  Initialize the encrypted string to the plain text.  This way,
%  nonalphabetic characters are passed through.
%
  crypt = plain;
%
%  Copy the plain text.
%
  copy = plain;
%
%  Capitalize the copy of the plain text.
%
  copy = upper ( copy );
%
%  Determine the numeric equivalents of the endpoints of the A-Z interval.
%
  aval = uint8 ( 'A' );
  zval = uint8 ( 'Z' );
%
%  Convert plain text characters to numbers which can index the code.
%
  for i = 1 : n
    ival = uint8 ( copy(i) );
    if ( aval <= ival && ival <= zval )
      jval = ival - aval + 1;
      crypt(i) = code(jval);
    end
  end
      
  return
end

