Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Pleac/rot13

From: Rebolinth::nodep::dds::nl at: 12-Oct-2003 13:29

Addons, still forgot to post them at rot13.org ;-) Regards, Norman. example (1) * the quick way * rot13: func [ char [char! string!] { returns a rotate 13 on alphanumeric charatcers } ] [ char: to-char char if any [ all [ char >= #"a" char <= #"m" ] all [ char >= #"A" char <= #"M" ] ] [ return char + 13 ] if any [ all [ char >= #"n" char <= #"z" ] all [ char >= #"N" char <= #"Z" ] ] [ return char - 13 ] return char ] example (2) * the lazy way * str1: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" str2: "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" rot13: func [ char ] [ either found? find str1 char [ return pick str2 index? find/case str1 char ][ return char ] ] example (3) * the long way * ; Define Global variables ROT13FRSMA: "abcdefghijklmnopqrstuvwxyz" ROT13TOSMA: "nopqrstuvwxyzabcdefghijklm" ROT13FRBIG: "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ROT13TOBIG: "NOPQRSTUVWXYZABCDEFGHIJKLM" Rot_13: func[ "Translate a string to ROT13" arg1 [string!] "String to be converted" /local encode ][ encode: "" while [(length? arg1) > 0][ either (to-integer first arg1) < 91 [ ; We are talking about capitals either attempt [index? find ROT13FRBIG first arg1][ encode: join encode pick ROT13TOBIG index? find ROT13FRBIG first arg1 ][ encode: join encode first arg1 ] ][ ; Small letters from here either attempt[index? find ROT13FRSMA first arg1][ encode: join encode pick ROT13TOSMA index? find ROT13FRSMA first arg1 ][ encode: join encode first arg1 ] ] arg1: next arg1 ] encode ] -- Conversation/lunch: "How do you Eat your Rebol in the Morning?"