RosettaCodeData/Task/Rot-13/S-BASIC/rot-13.basic

31 lines
746 B
Plaintext

comment
Return the rot13 transformation of s, preserving case and
passing non-alphabetic characters without change
end
function rot13(s = string) = string
var i, k = integer
var ch = char
var normal, rotated = string
normal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
rotated = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
for i = 1 to len(s)
ch = mid(s,i,1)
k = instr(1,normal,ch)
if k <> 0 then ch = mid(rotated,k,1)
mid(s,i,1) = ch
next i
end = s
rem - exercise the function
var plain, encoded = string
plain = "The quick brown fox jumps over the lazy dog."
encoded = rot13(plain)
print "Plain text: "; plain
print "Encoded : "; encoded
print "Decoded : "; rot13(encoded)
end