home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
clarion
/
encrypt.zip
/
CIPHER.CLA
next >
Wrap
Text File
|
1990-02-04
|
5KB
|
104 lines
MEMBER('ENCRYPT')
!==============================================================================!
! COPYRIGHT (C) 1990 by Randy Goodhew. !
! ALL RIGHTS RESERVED, WORLDWIDE. !
!------------------------------------------------------------------------------!
! Your comments are welcome. Please contact: !
! Randy Goodhew !
! PROFESSIONAL TECHNOLOGIES CONSULTANTS !
! 508 Greenup Street !
! Covington, KY 41011 !
! Phone: (606) 491-3020 !
!==============================================================================!
Encipher FUNCTION(L:PlainText,L:Password)
GROUP,PRE(L) !Local Group Variables
PlainText STRING(255) !Plain Text String
CipherText STRING(255) !Cipher Text String
Password STRING(30) !Password String
Len_Plain LONG !Length of Plain Text String
Len_Password LONG !Length of Password
c LONG !Password Character Position
n LONG !Loop Counter
END !group
CODE
!---------- Encipher Loop -----------------------------------------------
! This Encryption Method uses a double XORing technique:
! 1) Extract the ASCII Value of a character.
! 2) XOR the value using the ASCII value of a Password character as a mask.
! 3) XOR using the Encryption Loop Counter as a mask.
! 4) Then convert back to an ASCII character.
! This encryption algorithm will cycle through the Password and use each
! character as a mask. Therefore, the longer the Password, the better the
! encryption. The second XORing helps make the Cipher Text appear
! nonrepeating. A better technique would be to use pseudorandom numbers.
!------------------------------------------------------------------------
L:PlainText = CLIP(L:PlainText) !Clip Plain Text String
L:Password = CLIP(L:Password) !Clip Password String
L:Len_Plain = LEN(CLIP(L:Plaintext)) !Get length of Plain Text
L:Len_Password = LEN(CLIP(L:Password)) !Get length of Password
L:CipherText = '' !Clear Cipher Text String
L:c = 0 !Clear Position Counter
LOOP L:n = 1 TO L:Len_Plain BY 1 !Encryption Loop
L:c += 1 !Increment Position Counter
IF L:c > L:Len_Password THEN L:c = 1. !Reset Position Counter
L:CipherText = SUB(L:CipherText,1,(L:n - 1)) & | !Build Cipher Text String
CHR(BXOR(BXOR(VAL(SUB(L:PlainText,L:n,1)),VAL(SUB(L:Password,L:c,1))),L:n))
END !encryption loop
RETURN(L:CipherText) !Return Encrypted String
!====================================================================
Decipher FUNCTION(L:CipherText,L:Password)
GROUP,PRE(L) !Local Group Variables
PlainText STRING(255) !Plain Text String
CipherText STRING(255) !Cipher Text String
Password STRING(30) !Password String
Len_Cipher LONG !Length of Cipher Text String
Len_Password LONG !Length of Password String
a LONG !Value of Deciphered Character
b LONG !Value of Password Character
c LONG !Password Character Position
d LONG !Value of Cipher Text Character
n LONG !Decryption Loop Counter
END !group
CODE
!---------- Decipher Loop --------------------------------------------
! Reverse the process.
!---------------------------------------------------------------------
L:Len_Cipher = LEN(CLIP(L:CipherText)) !Get length of Cipher Text
L:Len_Password = LEN(CLIP(L:Password)) !Get length of Password
L:PlainText = '' !Clear Plain Text String
L:c = 0 !Clear Position Counter
LOOP L:n = 1 TO L:Len_Cipher BY 1 !Decryption Loop
L:c += 1
IF L:c > L:Len_Password THEN L:c = 1.
L:b = VAL(SUB(L:Password,L:c,1))
L:d = VAL(SUB(L:CipherText,L:n,1))
IF BXOR(L:d,L:n) = 0 !Test for NULL
L:a = L:b
ELSIF L:d = 32 !Test for Space (ASCII 32)
L:a = BXOR(BXOR(BXOR(L:d,L:b),L:n),32)
ELSE
L:a = BXOR(BXOR(L:d,L:b),L:n)
END !if
!-------------------------------------------------------------------
! Since Clarion converts NULLs to the Space symbol (ASCII 32),
! the above IF structure corrects the Decryption Process.
! Note: A NULL will appear in the Encrypted String if the character
! being XORed and mask character in the Password are the same.
!-------------------------------------------------------------------
L:PlainText = SUB(L:PlainText,1,(L:n - 1)) & CHR(L:a) !Build String
END !decryption loop
RETURN(L:PlainText) !Return Plain Text String