June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
18
Task/Caesar-cipher/Factor/caesar-cipher.factor
Normal file
18
Task/Caesar-cipher/Factor/caesar-cipher.factor
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
USING: io kernel locals math sequences unicode.categories ;
|
||||
IN: rosetta-code.caesar-cipher
|
||||
|
||||
:: cipher ( n s -- s' )
|
||||
[| c |
|
||||
c Letter? [
|
||||
c letter? CHAR: a CHAR: A ? :> a
|
||||
c a - n + 26 mod a +
|
||||
]
|
||||
[ c ] if
|
||||
] :> shift
|
||||
s [ shift call ] map ;
|
||||
|
||||
: encrypt ( n s -- s' ) cipher ;
|
||||
: decrypt ( n s -- s' ) [ 26 swap - ] dip cipher ;
|
||||
|
||||
11 "Esp bftnv mczhy qzi ufxapo zgpc esp wlkj ozr." decrypt print
|
||||
11 "The quick brown fox jumped over the lazy dog." encrypt print
|
||||
Loading…
Add table
Add a link
Reference in a new issue