Text encryption
#1
Ok, here is a simple program to encode text with a shifting cypher.

Usage:-
  crypt encode 1234 "your data"
  crypt decode 1234 "encoded data"

Code: (Select All)
$CONSOLE:ONLY
CLS
DIM SHARED AS STRING phrase, message, code
REDIM SHARED AS INTEGER sCode(0)
phrase = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
SplitCode
SELECT CASE LCASE$(COMMAND$(1))
    CASE "encode"
        en$ = EnCode
        PRINT "EnCode<", en$
        _CLIPBOARD$ = en$
        PRINT
        PRINT "encoded message has been copied to clipboard"
        SYSTEM
    CASE "decode"
        de$ = DeCode
        PRINT "DeCode>", de$
        _CLIPBOARD$ = de$
        SYSTEM
END SELECT

FUNCTION DeCode$
    DIM AS STRING t, h, e
    DIM AS INTEGER c
    c = 1
    h = UCASE$(COMMAND$(3))
    FOR i = 1 TO LEN(h)
        FOR x = 1 TO LEN(phrase)
            IF MID$(h, i, 1) = MID$(phrase, x, 1) THEN
                e = e + MID$(phrase, x - sCode(c), 1)
                EXIT FOR
            END IF
        NEXT x
        IF c = 4 THEN c = 1 ELSE c = c + 1
    NEXT i
    DeCode = dehex(e)

END FUNCTION

FUNCTION EnCode$
    DIM AS STRING t, h, e
    DIM AS INTEGER c
    c = 1
    h = toHex(COMMAND$(3))
    FOR i = 1 TO LEN(h)
        FOR x = 1 TO LEN(phrase)
            IF MID$(h, i, 1) = MID$(phrase, x, 1) THEN
                e = e + MID$(phrase, x + sCode(c), 1)
                EXIT FOR
            END IF
        NEXT x
        IF c = 4 THEN c = 1 ELSE c = c + 1
    NEXT i
    EnCode = e

END FUNCTION

SUB SplitCode
    REDIM sCode(LEN(COMMAND$(2))) AS INTEGER
    FOR i = i TO LEN(COMMAND$(2))
        sCode(i) = VAL(MID$(COMMAND$(2), i, 1))
    NEXT
END SUB

FUNCTION dehex$ (m AS STRING)
    DIM s AS STRING
    FOR i = 1 TO LEN(m) STEP 2
        s = s + CHR$(VAL("&h" + MID$(m, i, 2)))
        dehex = s
    NEXT

END FUNCTION

FUNCTION toHex$ (m AS STRING)
    DIM s AS STRING
    FOR i = 1 TO LEN(m)
        s = s + HEX$(ASC(MID$(m, i, 1)))
        toHex = s
    NEXT
END FUNCTION


Attached Files
.bas   crypt.bas (Size: 1.84 KB / Downloads: 69)
Reply


Messages In This Thread
Text encryption - by AtomicSlaughter - 11-17-2022, 10:59 AM
RE: Text encryption - by JRace - 11-17-2022, 07:59 PM
RE: Text encryption - by mnrvovrfc - 11-17-2022, 09:03 PM
RE: Text encryption - by bplus - 11-17-2022, 09:25 PM
RE: Text encryption - by JRace - 11-17-2022, 09:57 PM
RE: Text encryption - by bplus - 11-17-2022, 10:03 PM
RE: Text encryption - by SpriggsySpriggs - 11-17-2022, 10:03 PM
RE: Text encryption - by JRace - 11-17-2022, 10:22 PM
RE: Text encryption - by Jack - 11-17-2022, 10:58 PM



Users browsing this thread: 7 Guest(s)