I created an example of using dynamically generated ROT# style encryption/decrypting of a file based on the password entered as a proof of concept on Pete's QB site's forum back in February. I figured it was worth posting on NE as well as it works surprisingly well. Using BSAVE and BLOAD keeps the file from being able to be opened in a text editor and the ROT key is computed based on the password entered so it's dynamic. I won't say it's the most secure thing in the world but for what ever function a QB program may be doing these days where you want a user to be able to lock their data files, it should do well enough.
Link to download's page if you're interested:
Here
And because it's short, here's the whole program's source:
DECLARE SUB loadEncDataFile (fileName AS STRING)
DECLARE SUB saveEncDataFile (fileName AS STRING)
DECLARE SUB rotData (dataStr AS STRING, cipherKey AS INTEGER)
DECLARE FUNCTION getKey% (password AS STRING)
DECLARE FUNCTION unrotData$ (cipherKey AS INTEGER)
CLS
DIM SHARED encData(1 TO 512) AS INTEGER
dataStr$ = "This is a data string and it is currently not scrambled."
PRINT "DATA: "; dataStr$
INPUT "Enter a password: ", password$
cipherKey% = getKey%(password$)
CALL rotData(dataStr$, cipherKey%)
CALL saveEncDataFile("data.dat")
PRINT "Clearing memory..."
CLEAR
CALL loadEncDataFile("data.dat")
INPUT "Enter password to decode: ", password$
cipherKey% = getKey%(password$)
finalData$ = unrotData$(cipherKey%)
PRINT "Decoded: "; finalData$
END
FUNCTION getKey% (password AS STRING)
cipherKey% = 0
FOR i% = 1 TO LEN(password)
char$ = MID$(password, i%, 1)
cipherKey% = cipherKey% + ASC(char$) * i%
NEXT i%
PRINT "Cipher key: "; cipherKey%
getKey% = cipherKey%
END FUNCTION
SUB loadEncDataFile (fileName AS STRING)
DEF SEG = VARSEG(encData(1))
BLOAD fileName, VARPTR(encData(1))
DEF SEG
PRINT "Loaded file: "; fileName
END SUB
SUB rotData (dataStr AS STRING, cipherKey AS INTEGER)
FOR i% = 1 TO LEN(dataStr)
IF i% < UBOUND(encData) THEN
rotChar% = ASC(MID$(dataStr, i%, 1)) + cipherKey
encData(i%) = rotChar%
END IF
NEXT i%
END SUB
SUB saveEncDataFile (fileName AS STRING)
bytes% = LEN(encData(1)) * UBOUND(encData) + 1
DEF SEG = VARSEG(encData(1))
BSAVE fileName, VARPTR(encData(1)), bytes%
DEF SEG
PRINT "Saved file: "; fileName
END SUB
FUNCTION unrotData$ (cipherKey AS INTEGER)
outData$ = ""
FOR i% = 1 TO UBOUND(encData)
charVal% = encData(i%) - cipherKey
IF charVal% > 0 AND charVal% < 255 THEN
char$ = CHR$(charVal%)
outData$ = outData$ + char$
END IF
NEXT i%
unrotData$ = outData$
END FUNCTION