Skip to contents

This can be used to create (encrypt) and solve (decrypt) a Railfence Cipher. A Railfence Cipher maps each letter to a cosine wave of the specified height where each letter resides at an integer rail height.

The Railfence Cipher Wikipedia entry provides more information on the methods used: https://en.wikipedia.org/wiki/Rail_fence_cipher

Usage

railfence(x, n = 1, decrypt = FALSE)

Arguments

x

A vector to be encoded or decoded.

n

(Default: 1) The width of the rail to be used. A width of one will have no effect.

decrypt

(Default: FALSE) The default FALSE will encrypt while using TRUE will decrypt a given value of x.

Value

A character vector of length one that has been transformed

Examples

(e1 <- railfence("abcde", 2))
#> [1] "acebd"
railfence(e1, 2, decrypt = TRUE)
#> [1] "abcde"

(e2 <- railfence("cipheR is a great R package!", 4))
#> [1] "c gRaiRi r  kgpesaetpceh aa!"
railfence(e2, 4, decrypt = TRUE)
#> [1] "cipheR is a great R package!"

(e3 <- railfence("Isn't this fun?", 3))
#> [1] "Itius' hsfnnt ?"
railfence(e3, 3, decrypt = TRUE)
#> [1] "Isn't this fun?"