RosettaCodeData/Task/Caesar-cipher/Run-BASIC/caesar-cipher.basic

22 lines
523 B
Plaintext

input "Gimme a ofset:";ofst ' set any offset you like
a$ = "Pack my box with five dozen liquor jugs"
print " Original: ";a$
a$ = cipher$(a$,ofst)
print "Encrypted: ";a$
print "Decrypted: ";cipher$(a$,ofst+6)
FUNCTION cipher$(a$,ofst)
for i = 1 to len(a$)
aa$ = mid$(a$,i,1)
code$ = " "
if aa$ <> " " then
ua$ = upper$(aa$)
a = asc(ua$) - 64
code$ = chr$((((a mod 26) + ofst) mod 26) + 65)
if ua$ <> aa$ then code$ = lower$(code$)
end if
cipher$ = cipher$;code$
next i
END FUNCTION