This can be used to create (encrypt) and solve (decrypt) a Vigenere Cipher. A Vigenere cipher uses a table of alphabetic Caesar shifts for one to twenty-six. Each letter and corresponding key value determine the grid location to choose the obfuscated letter from.
The Vigenere Cipher Wikipedia entry provides more information on the methods used: https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
Arguments
- x
A vector to be encoded or decoded.
- key
A character vector of length one to use as a key
- decrypt
(Default:
FALSE
) The defaultFALSE
will encrypt while usingTRUE
will decrypt a given value ofx
.- keep_punctuation
(Default:
FALSE
) The defaultFALSE
will ignore case and punctuation and return a lowercase result.TRUE
will match the input's case and punctuation.
Examples
(e1 <- vigenere("abcde", "key"))
#> [1] "kfani"
vigenere(e1, "key", decrypt = TRUE)
#> [1] "abcde"
(e2 <- vigenere("cipheR is a great R package!", "key"))
#> [1] "mmnripswyqvckxpzeaueeo"
vigenere(e2, "key", decrypt = TRUE)
#> [1] "cipherisagreatrpackage"
(e3 <- vigenere("Isn't this fun?", "key", keep_punctuation = TRUE))
#> [1] "Swl'd xfsw der?"
vigenere(e3, "key", decrypt = TRUE, keep_punctuation = TRUE)
#> [1] "Isn't this fun?"