QB64 Phoenix Edition
_ROL & _ROR A quickie bit of crypto - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3)
+---- Forum: Programs (https://staging.qb64phoenix.com/forumdisplay.php?fid=7)
+---- Thread: _ROL & _ROR A quickie bit of crypto (/showthread.php?tid=860)



_ROL & _ROR A quickie bit of crypto - OldMoses - 09-05-2022

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. Wink

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$