Contributor: ANDREW EIGUS

The following is result of my work to make simple, fast, and enough
acceptable routine that will encrypt/decrypt any data with the given Key
string. It really works, it's far from RSA and DES, but it encrypts/decrypts
just as it will be _quite_ (impossibel? hard?) to restore the original data
without knowing a Key. BTW, i would recommend as long Key as possibel. ;)

This Eigus Encryption released to Public Domain, and no charge is required
for the author. Alsow, if you would have reccomendations, suggestions, ideas,
or stories to optimise my code, please do not hestitate to ask/tell/post.

Eigus Encryption may be included in SWAG. Thank you.

Unit Crypto;
  Copyright (c) 1994 by Andrew Eigus    Fidonet: 2:5100/33
  Eigus Encryption Routine source code for Borland Pascal 7.0
  Platforms: DOS, DPMI, Windows


  { use these above as values for ecCommand parameter for Encrypt procedure }
  ecEncode  = True;
  ecExtract = False;

procedure Encrypt(var Buffer; Count : word; Key : string; ecCommand : boolean);


Procedure Encrypt; assembler;
  SaveDS, SaveSI : word;
  N : byte;
  push ds
  lds si,Key
  xor ah,ah
  mov N,al
  mov bx,ax
  cmp bx,0
  je  @@5
  mov SaveDS,ds
  mov SaveSI,si
  lds si,Buffer
  les di,Buffer
  mov cx,Count
  jcxz @@5
  mov dl,al
  push ds
  push si
  mov ds,SaveDS
  mov si,SaveSI
  dec bx
  cmp bx,0
  jz  @@2
  lds si,Key
  mov bl,al
  add N,al
  or  ecCommand,ecExtract
  jz  @@3
  add dl,al
  sub dl,N
  not dl
  jmp @@4
  not dl
  add dl,N
  sub dl,al
  mov al,dl
  mov SaveDS,ds
  mov SaveSI,si
  pop si
  pop ds
  loop @@1
  pop ds
End; { Encrypt }



Program CryptoDemo;
Copyright (c) 1994 by Andrew Eigus  Fidonet: 2:5100/33
Demonstrates the use of unit CRYPTO.PAS

uses Crypto;

  Str, Key : string;

  Str := 'This is text to encrypt with Encrypt procedure'; { text to encrypt }
  Key := 'ExCaLiBeR'; { key string to use; longer -> safer ;I }
  WriteLn(#13#10'Original string: ''', Str, '''');
  Encrypt(Str[1], Length(Str), Key, ecEncode);
  WriteLn('Encrypted string: ''', Str, '''');
  Encrypt(Str[1], Length(Str), Key, ecExtract);
  WriteLn('Decrypted string: ''', Str, '''')

I hope that my CRYPTO unit might be useful for all of you. You may change my
code as you want.