Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Vigen-re-cipher/R/vigen-re-cipher.r
Normal file
18
Task/Vigen-re-cipher/R/vigen-re-cipher.r
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
mod1 = function(v, n)
|
||||
# mod1(1:20, 6) => 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2
|
||||
((v - 1) %% n) + 1
|
||||
|
||||
str2ints = function(s)
|
||||
as.integer(Filter(Negate(is.na),
|
||||
factor(levels = LETTERS, strsplit(toupper(s), "")[[1]])))
|
||||
|
||||
vigen = function(input, key, decrypt = F)
|
||||
{input = str2ints(input)
|
||||
key = rep(str2ints(key), len = length(input)) - 1
|
||||
paste(collapse = "", LETTERS[
|
||||
mod1(input + (if (decrypt) -1 else 1)*key, length(LETTERS))])}
|
||||
|
||||
message(vigen("Beware the Jabberwock, my son! The jaws that bite, the claws that catch!", "vigenerecipher"))
|
||||
# WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY
|
||||
message(vigen("WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY", "vigenerecipher", decrypt = T))
|
||||
# BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH
|
||||
Loading…
Add table
Add a link
Reference in a new issue