unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
Var FIN: file of char;
  FOUT: file of byte;
  s: char;
  inbyte: byte;
  outbyte: byte;
begin
  Form1.Opendialog1.Execute;
  AssignFile (FIN,Opendialog1.FileName);
  Reset (FIN);
  AssignFile (FOUT,Opendialog1.FileName+'.outtext');
  ReWrite (FOUT);
  While not(eof(FIN)) do
    begin
    Read (FIN,s); inbyte:=ord(s);
    if inbyte=0 then outbyte:=0;
    if inbyte=32 then outbyte:=2;
    if (inbyte>=Ord('A')) and (inbyte<=Ord('I')) then outbyte:=2*(inbyte-Ord('A'))+4;
    if (inbyte>Ord('I')) and (inbyte<=Ord('Z')) then outbyte:=2*(inbyte-Ord('A'))+4-1;
    if (inbyte=Ord('.')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 2;
    if (inbyte=Ord(',')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 3;
    if (inbyte=Ord('!')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 4;
    if (inbyte=Ord('"')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 5;
    if (inbyte=Ord('/')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 6;
    if (inbyte=Ord('(')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 7;
    if (inbyte=Ord(')')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 8;
    if (inbyte=Ord('?')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 9;

    if (inbyte=Ord('0')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 11;
    if (inbyte=Ord('1')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 13;
    if (inbyte=Ord('2')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 14;
    if (inbyte=Ord('3')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 16;
    if (inbyte=Ord('4')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 18;
    if (inbyte=Ord('5')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 20;
    if (inbyte=Ord('6')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 22;
    if (inbyte=Ord('7')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 24;
    if (inbyte=Ord('8')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 26;
    if (inbyte=Ord('9')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 28;

    if (inbyte=Ord(':')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 30;
    if (inbyte=Ord('+')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 31;
    if (inbyte=Ord('`')) then outbyte:=(Ord('Z')-Ord('A'))*2-1+4 + 32;


    Write (FOUT,outbyte);
    end;
  CloseFile(FIN);
  CloseFile(FOUT);
end;

end.
