program FrquencyShift (infile, outfile, input, output);

{This program is desigend to take the differnce between the most common lettter}
{of a frequency analysis and the most common letter in English text, "e", and}
{does a caesar shift of this difference}

var
   ch, letter : char;
   n : integer;

    infile,
    outfile  	: text;

procedure Input;
   {Determines the Caesar shift of "n" places, which is the difference between} 
   {"e" and the most common letter}

begin
   reset   (infile);
   rewrite (outfile);

   writeln('Most common letter was ');
   read(letter);
   n:= ord('e') - ord(letter);
end; {procedure Input}

procedure LowerCase (var Ch:char);
   {Reduces all uppercase letters to lowercase letters before applying}
   {deciphering sequence}

begin
   if Ch in ['A' .. 'Z'] then
      begin
         Ch:= chr(ord(Ch) -ord('A') + ord('a'));
	 assert (Ch in ['a' .. 'z']);
      end
end;

procedure LessThan (var Ch:char; N: integer);
   {Caesar shift procedure for values of n less than zero}

begin
     if N < 0 then
 begin
   if Ch in ['a'..chr(ord('z') + N)] then {the set of characters where the}
			{shift remains in the lowercase protion of ASCII code}   begin				   
	Ch := chr(ord(Ch) -N);		 
      end
   else if Ch in [chr(ord('z') + N - 1)..'z'] then {the set of characters where}
	{the shift would produce outputs outside of the lowercase portion}
      begin					   
	Ch := chr(ord(Ch) - 26 - N);		    
      end	
   end;				    
end; {procedure LessThan}

procedure GreaterThan (var Ch:char; N: integer);
   {Caesar shift procedure for values of n greater than zero}

begin
   if N > 0 then
      begin
	if Ch in [chr(ord('a') + N) .. 'z'] then
           begin
	      Ch:=chr(ord(Ch) - N);
	   end
        else if Ch in ['a' .. chr(ord('a') + N -1)] then
	   begin
	      Ch := chr(ord(Ch) + 26 - N);
	   end
   end;
end; {procedure GreaterThan}

begin		{Main program}
  Input;	{procedure}
      begin
         while not eof(infile) do
	    begin
	       if eoln(infile) then
	          begin
		     readln  (infile);
		     writeln (outfile);
      	          end
	       else
	          begin
		     read(infile, ch);		{encode text}
		     LowerCase(ch);		{procedure}
		     LessThan(ch, n);		{procedure}
		     GreaterThan(ch,n);		{procedure}
		     write(outfile, ch);	{procedure}
	       end; {else}
	    end;
      end;
end.


