09-05-2022, 09:36 PM
Having been wondering what bit rotation would be good for and seeing that it has applications in cryptography, here's a quick and easy scrambler. It might even fend off NSA for a few pico-seconds.
You'll need the new release for this one to work.
You'll need the new release for this one to work.
Code: (Select All)
'simple rotate encryption demo - by OldMoses
CLS
INPUT "Type a phrase ", a$
INPUT "enter a password ", ky$
PRINT "original phrase"
PRINT a$
DIM b(LEN(a$)) AS _UNSIGNED _BYTE ' phrase array
DIM e(LEN(a$)) AS _UNSIGNED _BYTE ' encrypted array
DIM d(LEN(a$)) AS _UNSIGNED _BYTE ' decrypted array
DIM k(LEN(ky$)) AS _UNSIGNED _BYTE ' keyword array
FOR x% = 1 TO LEN(ky$) ' configure keyword
k(x%) = ASC(ky$, x%)
NEXT x%
i% = 0
FOR x% = 1 TO LEN(a$) ' encrypt
b(x%) = ASC(a$, x%)
i% = i% + 1
IF i% > UBOUND(k) THEN i% = 1
e(x%) = _ROR(b(x%), k(i%))
e$ = e$ + CHR$(e(x%))
NEXT x%
PRINT
PRINT "encrypted phrase"
PRINT e$
PRINT
INPUT "password ", ps$
DIM p(LEN(ps$)) AS _UNSIGNED _BYTE ' password array
FOR x% = 1 TO LEN(ps$) ' configure password
p(x%) = ASC(ps$, x%)
NEXT x%
i% = 0
FOR x% = 1 TO LEN(e$) ' decrypt
b(x%) = ASC(e$, x%)
i% = i% + 1
IF i% > UBOUND(p) THEN i% = 1
d(x%) = _ROL(b(x%), p(i%))
d$ = d$ + CHR$(d(x%))
NEXT x%
PRINT
PRINT "decrypted phrase"
PRINT d$
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
sha_na_na_na_na_na_na_na_na_na: