]> gitweb.factorcode.org Git - factor.git/blob - extra/rot13/rot13.factor
scryfall: parse mtga deck format
[factor.git] / extra / rot13 / rot13.factor
1 ! Copyright (C) 2006 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math sequences io combinators ascii ;
4 IN: rot13
5
6 : rotate ( ch base -- ch ) [ - 13 + 26 mod ] [ + ] bi ;
7
8 : rot-letter ( ch -- ch )
9     {
10         { [ dup letter? ] [ CHAR: a rotate ] }
11         { [ dup LETTER? ] [ CHAR: A rotate ] }
12         [ ]
13     } cond ;
14
15 : rot13 ( string -- string ) [ rot-letter ] map ;
16
17 : rot13-demo ( -- )
18     "Please enter a string:" print flush
19     readln [
20         "Your string: " write dup print
21         "Rot13:       " write rot13 print
22     ] when* ;
23
24 MAIN: rot13-demo