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

Pleac/rot13

 [1/10] 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?"

 [2/10] from: Rebolinth:nodep:dds:nl at: 12-Oct-2003 13:42


Hello Karl Robillard (krobillard), Your Version is very Small but not a fully ROT13! Rot13 may only convert a - z A - Z Your version also converts anyother character (byte) too, so it wont work on binary strings.. This though works fine in a foreach loop (below), I believe it can be smaller, but i could not manage it to get it smaller after headbreaking ;-) rot13: func [ char [char!] { 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 ] (R)egards, Norman. -- Conversation/lunch: "How do you Eat your Rebol in the Morning?"

 [3/10] from: Rebolinth:nodep:dds:nl at: 12-Oct-2003 13:47


Speaking of ROT13, I had a fight with myself building a rot13 parser, using rebol using PARSE, though ...!! ...I could not manage it using BITSETS... Anyone dears to fight this ?? A honarable listing on the one that builds the smallest ROT13 using bitsets and parsing ;-) (R)egards, Norman. -- Conversation/lunch: "How do you Eat your Rebol in the Morning?"

 [4/10] from: joel:neely:fedex at: 12-Oct-2003 7:54


Hi, Norman, Here's one way, but I don't know about smallness... Rebolinth wrote:
> A honarable listing on the one that builds the smallest ROT13 using bitsets and parsing ;-) >
r13: func [s [string!] /local left right neither r13char c] [ left: charset [#"a" - #"m" #"A" - #"M"] right: charset [#"n" - #"z" #"N" - #"Z"] neither: complement union left right r13char: [ [ copy c left (c: +13 + to-char c) | copy c right (c: -13 + to-char c) | copy c neither] (prin to-char c) ] parse s [any r13char] ] -jn-

 [5/10] from: brett:codeconscious at: 13-Oct-2003 2:05


> A honarable listing on the one that builds the smallest ROT13 using
bitsets and parsing ;-) Compact but obscure. rot13: func [ string [string!] /local non-letter p ] [ non-letter: negate charset [#"a" - #"z" #"A" - #"Z"] parse/all/case string: copy string [ any [ some non-letter | p: skip (change p p/1 // 32 + 12 // 26 + 1 + and p/1 96) ] ] string ] Brett.

 [6/10] from: Rebolinth:nodep:dds:nl at: 12-Oct-2003 23:03


Hello Brett,
>Compact but obscure.
?? obscure ?? Mannnn...It took me some time to decypher that one ;-) Pritty good one !! (R)egards, Norman. -- Conversation/lunch: "How do you Eat your Rebol in the Morning?"

 [7/10] from: Rebolinth:nodep:dds:nl at: 12-Oct-2003 23:21


Hi Joel, I realy miss some Parsing technics here ;-) hahaha.. You know what amazes me the most? They way every rebol users builds its own functions here.. Ie. the 3 examples I posted today... The last one in the row of three was from a coworker of mine (the longest rot13 version though) but he is a BASIC programmer ;-) (explains the function build!) Not bad for someone who looked into the docs for 1 day ..:) The Second one was my first rot13 born out of speeds, needed it quickly... I think its a beginners rebol example but still not bad using the cookbook ;-) The first one was my seconds rebol rot13, Im a TCL programmer now you see where my logic came from, Im used using strings functions dont use regexp a lot though so i had to fight parsing real hard...did manage it fully though.. Your exmaple and the one from Brett mirror a deep Rebol programmer i must say..;-) Those look pritty cryptic but do work very well... So the philosofy of REBOL works out very good :-) Every man its tools building the same result with a different mind set.. amazing... Also the other examples of rot13.. Amazing how much they tell you about the person behind it ?-) But still ROT13 can be smaller in rebol... ;-) come you alll !!!!..heheheh... (R)egards, Norman...

 [8/10] from: krobillard:cox at: 12-Oct-2003 16:36


On Sunday 12 October 2003 04:42 am, you wrote:
> Hello Karl Robillard (krobillard), > > Your Version is very Small but not a fully ROT13! > Rot13 may only convert a - z A - Z > Your version also converts anyother character (byte) too, so it wont work > on binary strings..
Norman, I don't think it converts any others characters. Yes, it computes each char but the result can be the same as the input. I know it at least passes through all non alpha characters in the test data set. I didn't fully analyze how it works I just made the REBOL equivalent of one of the C versions. I like Carl Read's last version best. -Karl

 [9/10] from: antonr:iinet:au at: 14-Oct-2003 17:25


Here's my go at it: rot13: func [s [string!] /local result top][ result: copy s repeat n length? s [ top: either s/:n >= #"a" [97][65] ; determine upper or lowercase if (i: s/:n - top) < 26 [ ; only 26 letters in alphabet affected i: i + 13 // 26 ; perform rot13 poke result n to-char top + i ; insert new letter ] ] result ] Hmm, maybe we need a rot13 compiler to generate the long strings accurately ? :) Anton.

 [10/10] from: Rebolinth:nodep:dds:nl at: 15-Oct-2003 10:48


Hi Anton, A nice function too ;-) A lot of variations come up, very good :) Like Encloak/Deloak uses Bitset shitfting (pritty neetttt!!) I think also Rot13 could be done that way.. :-) Its an easy procedure like some exmaple we already have seen befor... I suspect that RT even has one lying on the shelf ;-) (R)egards, Norman. -- Conversation/lunch: "How do you Eat your Rebol in the Morning?"