$INCLUDE "RC4Asm.Rqh"
CONST RC4ASM_FINISHED_OK = 0
CONST RC4ASM_ERROR_PTR_KEY = 1
CONST RC4ASM_ERROR_LEN_KEY = 2
CONST RC4ASM_ERROR_PTR_DATAS = 3
CONST RC4ASM_ERROR_LEN_DATAS = 4
CONST RC4ASM_ERROR_PTR_STABLE = 5
CONST RC4ASM_ERROR_FILE_IN_CANT_BE_OPENED = 6
CONST RC4ASM_ERROR_CANT_CREATE_FILE_OUT = 7
CONST RC4ASM_ERROR_IBITSIZE_IN_RC4FILE_PIPE = 8
CONST RC4ASM_ERROR_UNEXPECTED = 255
FUNCTION GetRC4AsmErrorByName (iError AS LONG) AS STRING
SELECT CASE iError
CASE RC4ASM_FINISHED_OK
Result = " *** RC4ASM FINISHED_OK *** "
CASE RC4ASM_ERROR_PTR_KEY
Result = " *** RC4ASM ERROR_PTR_KEY *** "
CASE RC4ASM_ERROR_LEN_KEY
Result = " *** RC4ASM ERROR_LEN_KEY *** "
CASE RC4ASM_ERROR_PTR_DATAS
Result = " *** RC4ASM ERROR_PTR_DATAS *** "
CASE RC4ASM_ERROR_LEN_DATAS
Result = " *** RC4ASM ERROR_LEN_DATAS *** "
CASE RC4ASM_ERROR_PTR_STABLE
Result = " *** RC4ASM ERROR_PTR_STABLE *** "
CASE RC4ASM_ERROR_FILE_IN_CANT_BE_OPENED
Result = " *** RC4ASM ERROR FILE IN CANT BE OPENED ***"
CASE RC4ASM_ERROR_CANT_CREATE_FILE_OUT
Result = " *** RC4ASM ERROR CANT CREATE FILE OUT ***"
CASE RC4ASM_ERROR_IBITSIZE_IN_RC4FILE_PIPE
Result = " *** RC4ASM ERROR IBITSIZE_IN_RC4FILE_PIPE ***"
CASE ELSE
Result = " *** RC4ASM ERRONEOUS ERROR NUMBER :) " & STR$(iError) & " ***"
END SELECT
END FUNCTION
FUNCTION RC4File (PathFileNameIn AS STRING, PathFileNameOut AS STRING, Key AS STRING, iBitsSize AS LONG) AS LONG
DEFSTR sPathFileNameIn = PathFileNameIn, sPathFileNameOut = PathFileNameOut
DIM file2Rc4 AS QFILESTREAM
DIM fileRC4Out AS QFILESTREAM
DIM sTable AS STRING * 258
DEFINT iReturn
DEFINT iFileLengthLeft
DEFSTR sBits, sTmp
DEFSTR sKey = KEY
IF iBitsSize < 1 THEN Result = RC4ASM_ERROR_IBITSIZE_IN_RC4FILE_PIPE:EXIT FUNCTION
IF file2RC4.OPEN (sPathFileNameIn, 0) <> 0 THEN
IF fileRC4Out.OPEN (sPathFileNameOut, 65535) <> 0 THEN
iFileLengthLeft = file2RC4.Size
file2RC4.Position = 0
iReturn = RC4Init (sTable, sKey)
DO
IF iReturn = 0 THEN
IF iFileLengthLeft >= iBitsSize THEN
sBits = file2RC4.ReadBinStr (iBitsSize)
iReturn = RC4Pipe (sTable, sBits)
IF iReturn <> 0 THEN Result = iReturn:EXIT DO
fileRC4Out.WriteBinStr (sBits, iBitsSize)
iFileLengthLeft = iFileLengthLeft - iBitsSize
ELSE
sBits = file2RC4.ReadBinStr (iFileLengthLeft)
iReturn = RC4Pipe (sTable, sBits)
IF iReturn <> 0 THEN Result = iReturn:EXIT DO
fileRC4Out.WriteBinStr (sBits, iFileLengthLeft)
iFileLengthLeft = 0
END IF
ELSE
Result = iReturn
EXIT DO
END IF
LOOP UNTIL iFileLengthLeft = 0
fileRC4Out.CLOSE
ELSE
Result = RC4ASM_ERROR_CANT_CREATE_FILE_OUT
END IF
file2RC4.CLOSE
ELSE
Result = RC4ASM_ERROR_FILE_IN_CANT_BE_OPENED
EXIT FUNCTION
END IF
IF iFileLengthLeft <= 0 THEN Result = 0
END FUNCTION
$TYPECHECK OFF
|