Encrypt and decrypt text using the Caesar cipher.

caesar(text, shift = 3, decrypt = FALSE)

Arguments

text

String or vector of strings (numeric input will be coerced to string) to be ciphered or deciphered.

shift

A single whole number for how far to move the characters in the direction (positive or negative) you choose. If not a whole number, it will be rounded to nearest whole number.

decrypt

If TRUE, (not default) deciphers the coded text.

Value

String of the ciphered/deciphered text

Examples

# Please see this for more info. # https://en.wikipedia.org/wiki/Caesar_cipher caesar("Experience is the teacher of all things.")
#> [1] "HAshulhqfhclvcwkhcwhdfkhucricdoocwklqjva"
caesar("HAshulhqfhclvcwkhcwhdfkhucricdoocwklqjva", decrypt = TRUE)
#> [1] "Experience is the teacher of all things."
caesar("Veni, vidi, vici.", shift = 40)
#> [1] ",S1WKN9WRWKN9WQWL"
caesar(",S1WKN9WRWKN9WQWL", shift = 40, decrypt = TRUE)
#> [1] "Veni, vidi, vici."
caesar("No one is so brave that he is not disturbed by something unexpected.", shift = -12)
#> [1] "Bc[cb:[,g[gc[{f]j:[h>]h[>:[,g[bch[;,ghif{:;[{m[gca:h>,b<[ib:ld:}h:;`"
caesar("Bc[cb:[,g[gc[{f]j:[h>]h[>:[,g[bch[;,ghif{:;[{m[gca:h>,b<[ib:ld:}h:;`", shift = -12, decrypt = TRUE)
#> [1] "No one is so brave that he is not disturbed by something unexpected."