September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
23
Task/Caesar-cipher/8th/caesar-cipher.8th
Normal file
23
Task/Caesar-cipher/8th/caesar-cipher.8th
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
\ 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue