24 lines
608 B
Plaintext
24 lines
608 B
Plaintext
\ Ensure the output char is in the correct range:
|
|
: modulate \ char base -- char
|
|
tuck n:- 26 n:+ 26 n:mod n:+ ;
|
|
|
|
\ Symmetric Caesar cipher. Input is text and number of characters to advance
|
|
\ (or retreat, if negative). That value should be in the range 1..26
|
|
: caesar \ intext key -- outext
|
|
>r
|
|
(
|
|
\ Ignore anything below '.' as punctuation:
|
|
dup '. n:> if
|
|
\ Do the conversion
|
|
dup r@ n:+ swap
|
|
\ Wrap appropriately
|
|
'A 'Z between if 'A else 'a then modulate
|
|
then
|
|
) s:map rdrop ;
|
|
|
|
"The five boxing wizards jump quickly!"
|
|
dup . cr
|
|
1 caesar dup . cr
|
|
-1 caesar . cr
|
|
bye
|