37 lines
759 B
Plaintext
37 lines
759 B
Plaintext
'
|
|
' Caesar cypher
|
|
'
|
|
OPENW 1 ! Creates a window for handling input/output
|
|
CLEARW 1
|
|
INPUT "string to encrypt ";text$
|
|
INPUT "encryption key ";key%
|
|
encrypted$=@encrypt$(UPPER$(text$),key%)
|
|
PRINT "Encrypted: ";encrypted$
|
|
PRINT "Decrypted: ";@decrypt$(encrypted$,key%)
|
|
'
|
|
PRINT "(Press any key to end program.)"
|
|
~INP(2)
|
|
CLOSEW 1
|
|
'
|
|
FUNCTION encrypt$(text$,key%)
|
|
LOCAL result$,i%,c%
|
|
result$=""
|
|
FOR i%=1 TO LEN(text$)
|
|
c%=ASC(MID$(text$,i%))
|
|
IF c%<ASC("A") OR c%>ASC("Z") ! don't encrypt non A-Z
|
|
result$=result$+CHR$(c%)
|
|
ELSE
|
|
c%=c%+key%
|
|
IF c%>ASC("Z")
|
|
c%=c%-26
|
|
ENDIF
|
|
result$=result$+CHR$(c%)
|
|
ENDIF
|
|
NEXT i%
|
|
RETURN result$
|
|
ENDFUNC
|
|
'
|
|
FUNCTION decrypt$(text$,key%)
|
|
RETURN @encrypt$(text$,26-key%)
|
|
ENDFUNC
|