Rot-13: Difference between revisions

m
→‎{{header|An alternate approach}}: Code cleanup of 3rd S-BASIC approach
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:
</pre>
 
Still a third approach makes use of S-BASIC's awkward (and probablypoorly little-useddocumented) 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">
varfunction rot13(s, tr= string) = string:127
var tr = string:127
rem - set up translation table
tr = space$(31) + " !" + chr(34) + "#$%&'()*+,-./0123456789" + \
tr = tr + ":;<=>?@NOPQRSTUVWXYZABCDEFGHIJKLM[\]^_`" + \
tr = tr + "nopqrstuvwxyzabcdefghijklm{|}~"
send = xlate(s,tr)
 
rem - set uptest the translation stringfunction
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
splain = "The quick brown fox jumps over the lazy dog."
s = xlate(s,tr)
print "Rotated Plain text: "; splain
sencrypted = xlaterot13(s,trplain)
print "Restored Encrypted : "; sencrypted
print "Restored : "; rot13(encrypted)
 
end
Anonymous user