` Printed Icetips Article

Icetips Article



Par2: String Encryption Algorithm
2001-01-08 -- Randy Goodhew
 
Be my guest:

!===========================================================
eqCrypt            PROCEDURE(*STRING pIntext,CONST *STRING
pPass,<*STRING pOutText>) !returns ULONG
!===========================================================
! Copyright 2001 Randy Goodhew. ALL RIGHTS RESERVED.
! Prototype:  eqCrypt  PROCEDURE(*STRING InText,           |
!                                CONST *STRING password,   |
!                               <*STRING OutText>),LONG
! Parameters:
!    InText   - the buffer of text to be encrypted/decrypted
!    Password - the password (will be CLIPped of trailing spaces)
!    OutText  - omittable, the buffer that will receive the output.
!               If omitted, the Intext buffer will be over written.
! Returns:      the number of bytes processed.
!
! NOTE: On a 200 MHz Pentium computer, this procedure will
! encrypt/decrypt greater than 6,000,000 characters per second.
! This is a symmetric encryption algorithm. The same password
! must be used for both encryption and decryption. The password
! is case sensitive. If the password is blank, no text will be
! processed.
!===========================================================
OutRef             &STRING            ! output reference
Len                LONG,AUTO          ! length of password
J                  LONG,AUTO          ! text loop counter
K                  LONG,AUTO          ! password loop counter
Result             LONG,AUTO          ! number of characters
  CODE
  Len = LEN(CLIP(pPass))               ! get clipped length of password
  IF Len                               
    DO R_Process                       ! process if there is a password
  ELSE
    Result = 0                         ! return "0" if no password
  END !if
  RETURN(Result)                       ! return bytes processed
!-----------------------------------------------------------
R_Process          ROUTINE
  IF OMITTED(3)                        ! test for third parameter
    OutRef &= pInText                  ! write-back to first parameter
  ELSE                                 ! if NOT Omitted(2)
    OutRef &= pOutText                 ! write-back to second parameter
  END !if
  ! Set Result to smaller of the two:
  Result = CHOOSE(SIZE(pInText) >
SIZE(OutRef),SIZE(OutRef),SIZE(pInText))
  K = 1                                ! initialize password counter
  LOOP J = 1 TO Result BY 1            ! loop thru input text
    ! encrypt/decrypt each text character:
    OutRef[J] = CHR(BXOR(VAL(pInText[J]),VAL(pPass[K]))) ! See asm01
    K = CHOOSE(K = Len,1,K + 1)        ! adjust password counter
  END !loop
  OutRef &= NULL                       ! uninitialize reference
  EXIT

asm01  !----------------------------------------------------
  OMIT('***asm01***')
  This is a disassembly of the Clarion code that performs the
  actual encryption/decryption. Note that it is pure register
  based operations. There are no RTL calls or stack operations.
  ----------------------------
  mov  ebx,[edx][-14H]
  mov  eax,[edx][-1CH]
  mov  cl,[ebx][eax][-1]
  mov  ebx,[edx][-28H]
  mov  eax,[edx][-18H]
  xor  cl,[ebx][eax][-1]
  mov  [ebp][-9],cl
  mov  al,[ebp][-9]
  mov  [ebp][-0AH],al
  mov  ecx,[edx][-0CH]
  mov  ebx,[edx][-1CH]
  mov  al,[ebp][-0AH]
  mov  [ecx][ebx][-1],al
  ----------------------------
  ***asm01***



Printed November 21, 2024, 1:02 pm
This article has been viewed/printed 35236 times.