Caesar
Implements the Caesar cipher.
Syntax
-
Caesar(s, n)
-
s
is a string -
n
is an integer
-
Description
If s
is a string and n
an integer, then Caesar(s, n)
returns s
transformed using the Caesar cipher with shift n
.
Note that s ↦ Caesar(s, 0)
is the identity function on strings and that the inverse of s ↦ Caesar(s, N)
is s ↦ Caesar(s, −N)
for every integer N
. Also, Caesar(s, N + k⋅26) = Caesar(s, N)
for all strings s
, integers N
and integers k
.
Examples
Alice ≔ ExampleData("Alice in Wonderland")
ALICE’S ADVENTURES IN WONDERLAND Lewis Carroll THE MILLENNIUM FULCRUM EDITION 3.0 CHAPTER I. Down the Rabbit-Hole Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, ‘and what is the use of a book,’ thought Alice ‘without pictures or conversations?’ So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her. There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, ‘Oh dear! Oh dear! I shall be late!’ (when she thought it over afterwards, it occurred to her that she ought to have wondered a…
Caesar(Alice, 10)
KVSMO’C KNFOXDEBOC SX GYXNOBVKXN Vogsc Mkbbyvv DRO WSVVOXXSEW PEVMBEW ONSDSYX 3.0 MRKZDOB S. Nygx dro Bkllsd-Ryvo Kvsmo gkc loqsxxsxq dy qod fobi dsbon yp csddsxq li rob cscdob yx dro lkxu, kxn yp rkfsxq xydrsxq dy ny: yxmo yb dgsmo cro rkn zoozon sxdy dro lyyu rob cscdob gkc boknsxq, led sd rkn xy zsmdeboc yb myxfobckdsyxc sx sd, ‘kxn grkd sc dro eco yp k lyyu,’ dryeqrd Kvsmo ‘gsdryed zsmdeboc yb myxfobckdsyxc?’ Cy cro gkc myxcsnobsxq sx rob ygx wsxn (kc govv kc cro myevn, pyb dro ryd nki wkno rob poov fobi cvoozi kxn cdezsn), grodrob dro zvokcebo yp wkusxq k nksci-mrksx gyevn lo gybdr dro dbyelvo yp qoddsxq ez kxn zsmusxq dro nkscsoc, grox cennoxvi k Grsdo Bkllsd gsdr zsxu oioc bkx mvyco li rob. Drobo gkc xydrsxq cy FOBI bowkbuklvo sx drkd; xyb nsn Kvsmo drsxu sd cy FOBI wemr yed yp dro gki dy rokb dro Bkllsd cki dy sdcovp, ‘Yr nokb! Yr nokb! S crkvv lo vkdo!’ (grox cro dryeqrd sd yfob kpdobgkbnc, sd ymmebbon dy rob drkd cro yeqrd dy rkfo gyxnobon k…