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
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.
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:
Statistics: Posted by Anthony.R.Brown — Tue May 25, 2021 2:52 am
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
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.
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:
Statistics: Posted by Erik — Tue Feb 23, 2021 12:23 am
Statistics: Posted by Anthony.R.Brown — Sat Feb 20, 2021 8:59 am
Statistics: Posted by burger2227 — Tue Feb 16, 2021 5:53 pm
Statistics: Posted by Anthony.R.Brown — Tue Feb 09, 2021 9:52 am