fork download
  1. ! Copyright (C) 2006 Daniel Ehrenberg
  2. ! See http://f...content-available-to-author-only...e.org/license.txt for BSD license.
  3. USING: kernel math sequences strings 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
  25.  
  26. rot13-demo
  27.  
Success #stdin #stdout 0.23s 163968KB
stdin
Hello World!
stdout
Please enter a string:
Your string: Hello World!
Rot13:       Uryyb Jbeyq!