Hi Stephen,

Here's the one I'd submitted to REBOL org.
By premanipulating the string you can use a simple Select/Case

rot-13: func [
{Converts a string to or from Rot-13}
data [any-string!]
/local scrambled rot-chars rot-char
][
rot-chars:
{anabobcpcdqderefsfgtghuhivijwjkxklylmzmANABOBCPCDQDEREFSFGTGHUHIVIJWJKXKLYLMZ
M}
scrambled: copy ""

foreach char data [
    if none? (rot-char: select/case rot-chars char) [rot-char: char]
    insert tail scrambled :rot-char
]
   return scrambled
]

Also in the script at REBOL org is a generic ROT function that allows any ROT
+ or - on any specified key-set. Which is very handy if you are doing the code
challenge in The Code Book by Simon Singh. It easily solves the stage2 code.

Cheers

Allen K


----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, November 08, 1999 9:40 AM
Subject: [REBOL] Rot 13


> Saw a rot13 inREBOL at http://ucsub.colorado.edu/~kominek/rot13/rebol/
>
> Thought it unduly complicated so gave it a try myself.
>
> Here's my solution. Any improvements?
>
> REBOL [
>         Title: "Rot13"
>         Author: "Stephen B. Coulson"
>         Purpose: {To do a classic rot13 of course}
> ]
>
> table:
"nopqrstuvwxyzabcdefghijklmnopqrstuvwxyzNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXY
Z"
> rot13: func [target/local char][target: "" either error? try [table: skip
find/case head table char 13][append target char][append target first table]]
> rotme: ask "Type the string to rot :"
> print foreach letter rotme [rot13 letter]
>
>
> --
> + _                     /^^      (   Stephen B. Coulson            )   +
> |(_ [_  _  _ [_  _  _   |OO   O (  e-mail: [EMAIL PROTECTED]      ) |
> |,_)[_ (-'[_)[ )(-'[ )  @ \  o  ( http://members.axion.net/~scoulson ) |
> +       ~ [      ~      |o~ .                                          +
>
>

Reply via email to