Created
June 8, 2016 11:57
-
-
Save janfait/043886b282bd71fdc92d6f1274e26990 to your computer and use it in GitHub Desktop.
encryption function which is, well, impossible to decrypt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
encrypt <- function(v) { | |
#get uniques | |
vU <- unique(v) | |
vU <- vU[!is.na(vU) & vU!=""] | |
#apply the encryption over a vector | |
vE <- sapply(vU, function(x){ | |
oL <- c(LETTERS, letters) | |
oN <- 0:9 | |
sL <- sample(oL) | |
sN <- sample(oN) | |
x<-chartr(paste(oL,collapse=""), paste(sL,collapse=""),x) | |
x<-chartr(paste(oN,collapse=""), paste(sN,collapse=""),x) | |
x | |
}) | |
#create mapping data frame, old unique vector elemetns as o, replacement vector as n | |
mapping <- data.frame(o=vU,n=vE) | |
mapping <- rbind(mapping,c(o="",n="")) | |
#map back to original values | |
vE[match(v,mapping$o)] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment