function crypt = atbash ( plain )

%*****************************************************************************80
%
%% atbash() encrypts or decrypts a string using the ATBASH code.
%
%  Discussion:
%
%    Only the alphabetic characters will be encrypted.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    03 October 2016
%
%  Author:
%
%    John Burkardt
%
%  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;
%
%  Determine the numeric equivalents of the endpoints of the A-Z and a-z intervals.
%
  small_a = uint8 ( 'a' );
  small_z = uint8 ( 'z' );
  big_a = uint8 ( 'A' );
  big_z = uint8 ( 'Z' );
%
%  Convert plain text characters to unsigned integers,
%  and reverse the index.
%
  for i = 1 : n
    ival = uint8 ( plain(i) );
    if ( small_a <= ival && ival <= small_z )
      jval = small_a + small_z - ival;
      crypt(i) = char(jval);
    elseif ( big_a <= ival && ival <= big_z )
      jval = big_a + big_z - ival;
      crypt(i) = char(jval);
    end
  end
      
  return
end

