First I created a function that gives me a cryptography pattern
plugboard <- function(){
matrix(sample(letters, 26), nrow = 2, ncol = 13)
}
It gives me a Matrix in which every letter (lowcase) is paired with another.
Now i need to create another function that or code or decode in this cryptography, therefore if I have:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[1,] "v" "h" "k" "a" "w" "l" "f" "d" "u" "r" "t" "m" "s"
[2,] "p" "q" "b" "g" "x" "y" "i" "n" "z" "o" "j" "e" "c"
Then if I type in this new function "HOUSE" or "house" it will give me: "qrzcm" and if i type "qrzcm" it gives me "house".
I tried doing the following:
ATdecoder <- function(word){
word <- x
pat <- data.frame(plugboard())
tolower(x)
x = gsub(pat$V1, pat$V2, x)
}
But I am struggling putting this to work.
Please help