RosettaCodeData/Task/Caesar-cipher/Forth/caesar-cipher.fth

20 lines
415 B
Forth
Raw Permalink Normal View History

2023-10-02 18:11:16 -07:00
: caesar ( c n -- c )
2023-07-01 11:58:00 -04:00
over 32 or [char] a -
dup 0 26 within if
over + 25 > if 26 - then +
else 2drop then ;
2023-10-02 18:11:16 -07:00
: caesar-string ( n str len -- )
over + swap do i c@ over caesar i c! loop drop ;
2023-07-01 11:58:00 -04:00
2023-10-02 18:11:16 -07:00
: caesar-inverse ( n -- 'n ) 26 swap - 26 mod ;
2023-07-01 11:58:00 -04:00
2variable test
s" The five boxing wizards jump quickly!" test 2!
2023-10-02 18:11:16 -07:00
3 test 2@ caesar-string
2023-07-01 11:58:00 -04:00
test 2@ cr type
2023-10-02 18:11:16 -07:00
3 caesar-inverse test 2@ caesar-string
2023-07-01 11:58:00 -04:00
test 2@ cr type