Rot-13: Difference between revisions

Content added Content deleted
imported>KayproKid
(→‎{{header|S-BASIC}}: added additional approach)
imported>KayproKid
m (→‎{{header|An alternate approach}}: Code cleanup of 3rd S-BASIC approach)
Line 5,638: Line 5,638:
</pre>
</pre>


Still a third approach makes use of S-BASIC's awkward (and probably little-used) XLATE function, which transforms each character in the input string by using its ASCII value as an index into the translation string.
Still a third approach makes use of S-BASIC's awkward (and poorly documented) XLATE function, which transforms each character in the input string by using its ASCII value as an index into the translation string.
<syntaxhighlight lang = "basic">
<syntaxhighlight lang = "basic">
var s, tr = string:127
function rot13(s = string) = string
var tr = string:127
rem - set up translation table
tr = space$(31) + " !" + chr(34) + "#$%&'()*+,-./0123456789" + \
":;<=>?@NOPQRSTUVWXYZABCDEFGHIJKLM[\]^_`" + \
"nopqrstuvwxyzabcdefghijklm{|}~"
end = xlate(s,tr)


rem - set up the translation string
rem - test the function
tr = space$(31) + " !" + chr(34) + "#$%&'()*+,-./0123456789"
tr = tr + ":;<=>?@NOPQRSTUVWXYZABCDEFGHIJKLM[\]^_`"
tr = tr + "nopqrstuvwxyzabcdefghijklm{|}~"


var plain, encrypted = string
s = "The quick brown fox jumps over the lazy dog."

print "Plain text: "; s
plain = "The quick brown fox jumps over the lazy dog."
s = xlate(s,tr)
print "Rotated : "; s
print "Plain text: "; plain
s = xlate(s,tr)
encrypted = rot13(plain)
print "Restored : "; s
print "Encrypted : "; encrypted
print "Restored : "; rot13(encrypted)


end
end