| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! Copyright (C) 2006 Daniel Ehrenberg | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-02-01 19:26:32 -05:00
										 |  |  | USING: kernel math sequences strings io combinators ascii ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: rot13 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-05 23:22:21 -05:00
										 |  |  | : rotate ( ch base -- ch ) [ - 13 + 26 mod ] [ + ] bi ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : rot-letter ( ch -- ch )
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         { [ dup letter? ] [ CHAR: a rotate ] } | 
					
						
							|  |  |  |         { [ dup LETTER? ] [ CHAR: A rotate ] } | 
					
						
							| 
									
										
										
										
											2008-04-11 13:57:43 -04:00
										 |  |  |         [ ] | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     } cond ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : rot13 ( string -- string ) [ rot-letter ] map ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : rot13-demo ( -- )
 | 
					
						
							|  |  |  |     "Please enter a string:" print flush
 | 
					
						
							|  |  |  |     readln [ | 
					
						
							|  |  |  |         "Your string: " write dup print
 | 
					
						
							|  |  |  |         "Rot13:       " write rot13 print
 | 
					
						
							|  |  |  |     ] when* ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MAIN: rot13-demo |