[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result
Pete's QBASIC Site Discuss QBasic, Freebasic, QB64 and more 2021-05-25T02:52:37-05:00 http://www.petesqbsite.com/phpBB3/app.php/feed/topic/14862 2021-05-25T02:52:37-05:00 2021-05-25T02:52:37-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=39107#p39107 <![CDATA[Re: Is it Possible to Password protect a Program External DATA File ?]]>
It's not password protecting but what about using BSAVE/BLOAD to save and load the data files? That way it's stored in binary so you can't just open it up in a text editor to see the contents and it's also faster than regular reading/writing to text files using the old "OPEN filename for INPUT AS #1..." as you can load the whole file into an array when you BLOAD.

I guess you could add another layer of obfuscation by doing a ROT13 type idea like Burger's first suggestion on top of BSAVE/BLOAD.

Another idea is still use BSAVE/BLOAD but instead of hard coding the ROT number, base the ROT encrypt/decrypt on the password provided by the user. That way you don't actually store any password, but it's still the key to unscramble the data in the data file.

Here's a quick example I threw together that works.. though with any home grown encryption, it's not really secure.

Code:

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)CLSDIM SHARED encData(1 TO 512) AS INTEGERdataStr$ = "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..."CLEARCALL loadEncDataFile("data.dat")INPUT "Enter password to decode: ", password$cipherKey% = getKey%(password$)finalData$ = unrotData$(cipherKey%)PRINT "Decoded: "; finalData$ENDFUNCTION 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 FUNCTIONSUB loadEncDataFile (fileName AS STRING)    DEF SEG = VARSEG(encData(1))    BLOAD fileName, VARPTR(encData(1))    DEF SEG    PRINT "Loaded file: "; fileNameEND SUBSUB 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 SUBSUB 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: "; fileNameEND SUBFUNCTION 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
The program takes the data string and adds the password key to each character. Then saves it using bsave and clears the memory. After that, it loads the data back into memory using bload and attempts to undo the scramble using the 2nd prompted for password.

On success, it displays the unscrambled string. On failures, it will either display nothing if the calculated integer value is too large or small to be represented as ASCII or potentially garbage characters based on a wrong calculated offset.

Example successful output:

Code:

DATA: This is a data string and it is currently not scrambled.Enter a password: passwordCipher key: 3970Saved file: data.datClearing memory...Loaded file: data.datEnter password to decode: passwordCipher key: 3970Decoded: This is a data string and it is currently not scrambled.
Example of wrong decrypt password:

Code:

DATA: This is a data string and it is currently not scrambled.Enter a password: passwordCipher key: 3970Saved file: data.datClearing memory...Loaded file: data.datEnter password to decode: wrongCipher key: 1635Decoded: 
What it looks like if you try to view contents of data.dat outsite of bload/bsave:
Image


That looks Amazing! Eric :)

Statistics: Posted by Anthony.R.Brown — Tue May 25, 2021 2:52 am


]]>
2021-02-23T00:23:13-05:00 2021-02-23T00:23:13-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=39064#p39064 <![CDATA[Re: Is it Possible to Password protect a Program External DATA File ?]]>
I guess you could add another layer of obfuscation by doing a ROT13 type idea like Burger's first suggestion on top of BSAVE/BLOAD.

Another idea is still use BSAVE/BLOAD but instead of hard coding the ROT number, base the ROT encrypt/decrypt on the password provided by the user. That way you don't actually store any password, but it's still the key to unscramble the data in the data file.

Here's a quick example I threw together that works.. though with any home grown encryption, it's not really secure.

Code:

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)CLSDIM SHARED encData(1 TO 512) AS INTEGERdataStr$ = "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..."CLEARCALL loadEncDataFile("data.dat")INPUT "Enter password to decode: ", password$cipherKey% = getKey%(password$)finalData$ = unrotData$(cipherKey%)PRINT "Decoded: "; finalData$ENDFUNCTION 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 FUNCTIONSUB loadEncDataFile (fileName AS STRING)    DEF SEG = VARSEG(encData(1))    BLOAD fileName, VARPTR(encData(1))    DEF SEG    PRINT "Loaded file: "; fileNameEND SUBSUB 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 SUBSUB 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: "; fileNameEND SUBFUNCTION 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
The program takes the data string and adds the password key to each character. Then saves it using bsave and clears the memory. After that, it loads the data back into memory using bload and attempts to undo the scramble using the 2nd prompted for password.

On success, it displays the unscrambled string. On failures, it will either display nothing if the calculated integer value is too large or small to be represented as ASCII or potentially garbage characters based on a wrong calculated offset.

Example successful output:

Code:

DATA: This is a data string and it is currently not scrambled.Enter a password: passwordCipher key: 3970Saved file: data.datClearing memory...Loaded file: data.datEnter password to decode: passwordCipher key: 3970Decoded: This is a data string and it is currently not scrambled.
Example of wrong decrypt password:

Code:

DATA: This is a data string and it is currently not scrambled.Enter a password: passwordCipher key: 3970Saved file: data.datClearing memory...Loaded file: data.datEnter password to decode: wrongCipher key: 1635Decoded: 
What it looks like if you try to view contents of data.dat outsite of bload/bsave:
Image

Statistics: Posted by Erik — Tue Feb 23, 2021 12:23 am


]]>
2021-02-20T08:59:56-05:00 2021-02-20T08:59:56-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=39060#p39060 <![CDATA[Re: Is it Possible to Password protect a Program External DATA File ?]]>
You could rewrite the file shifting the text to another ASCII symbol if it is not something critical. I did that for a game I made by adding 30 to the ASC value into CHR$ and printing it into the file so a user would not cheat with famous quotes in a Crypto game.

Another way to do it is to actually have the program hold the DATA and have your program create the text file when run, but that may slow the program down if the data is large. Qbasic in DOS can write new data to the end of your program too...

Hi burger2227

It would be a really great solution if it was possible as you say "Another way to do it is to actually have the program hold the DATA and have your program create the text file when run" :)
And as you mentioned it may Slow the program down :( which I imagine it would and the program I am talking about needs to be as fast as possible! as it would be reading and writing to thousands of lines of DATA. Maybe if the DATA could be compressed it might work faster ?



A.R.B :)

Statistics: Posted by Anthony.R.Brown — Sat Feb 20, 2021 8:59 am


]]>
2021-02-16T17:53:32-05:00 2021-02-16T17:53:32-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=39059#p39059 <![CDATA[Re: Is it Possible to Password protect a Program External DATA File ?]]>
Another way to do it is to actually have the program hold the DATA and have your program create the text file when run, but that may slow the program down if the data is large. Qbasic in DOS can write new data to the end of your program too...

Statistics: Posted by burger2227 — Tue Feb 16, 2021 5:53 pm


]]>
2021-02-09T09:52:39-05:00 2021-02-09T09:52:39-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=39056#p39056 <![CDATA[Is it Possible to Password protect a Program External DATA File ?]]> The Password idea was the first idea I thought of when thinking about how to do this ? so every time you want to access the File for reading and writing it would have to load the Password...which is not so convenient :( so maybe there is another way to do it ?
I would like to do this to protect the External DATA and of course it has to also be protected from other ways of accessing the File ?



A.R.B :)

Statistics: Posted by Anthony.R.Brown — Tue Feb 09, 2021 9:52 am


]]>