Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
UU Encoding and Decoding
See more Encryption Examples
Demonstrates how to UU encode and decode.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Crypt2;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
crypt: TCrypt2;
s1: string;
s2: string;
s3: string;
crypt2: TCrypt2;
begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
crypt := TCrypt2.Create;
s1 := 'This string is to be UU encoded';
crypt.UuMode := '666';
crypt.UuFilename := 'something.txt';
// UU encode:
s2 := crypt.EncodeString(s1,'ansi','uu');
// Note: Call crypt.Encode instead of crypt.EncodeString
// to UU encode binary bytes (i.e. non-text binary data).
WriteLn(s2);
// UU decode:
crypt2 := TCrypt2.Create;
s3 := crypt2.DecodeString(s2,'ansi','uu');
// Note: Likewise, call crypt.Decode to decode non-text binary data.
WriteLn(s3);
// Show the file permissions mode and filename found
// in the UU encoded data:
WriteLn('UuMode = ' + crypt2.UuMode);
WriteLn('UuFilename = ' + crypt2.UuFilename);
crypt.Free;
crypt2.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.