Basic file encryptor
Don't try this on important files as it has not been tested
**********************
DIM string1(16384) AS STRING
DIM string2(16384) AS STRING
DIM LFILE AS _UNSIGNED LONG
DIM FPOS AS _UNSIGNED LONG
DIM NBYTES AS _UNSIGNED LONG
FPOS = 1
string1 = string$(16384,"a") 'string1 could randomized for better security
OPEN TEST.TXT FOR BINARY AS #1
LFILE = LOF (1)
DO
IF LFILE = 0 THEN EXIT DO
IF LFILE < 16384 THEN
GET #1, ,string2(LFILE) 'file read
FPOS = FPOS + LFILE 'FPOS = file position after GET
nbytes = LFILE
GOSUB XORstring2 'encrypt or decrypt
SEEK 1, FPOS - LFILE 'adjust file pointer
PUT #1, ,string2(LFILE) 'file write
LFILE = 0
END IF
IF LFILE =>16384 THEN
GET #1, ,string2(16384) 'file read
FPOS = FPOS + 16384 'FPOS = file position after GET
nbytes = 16384
GOSUB XORstring2 'encrypt or decrypt
SEEK 1, FPOS - 16384 'adjust file pointer
PUT #1, ,string2(16384) 'file write
LFILE = LFILE - 16384
END IF
LOOP
CLOSE 1
END
XORstring2:
FOR x% = 1 to nbytes
a$ = MID$(string1),x%,1)
b$ = MID$(string2),x%,1)
b$ xor a$
MID$(string2),x%,1) = b$
NEXT x%
RETURN
*****
Question
In the above code is:
DIM string1(16384) AS STRING
equivalent to
DIM string1 AS STRING * 16384
for the application as shown?
****