I am trying to encrypt postcodes (zipcodes) which, in my datasets, are strings with 8 characters, including spaces. By referring to other help files and other R resources I've built some (clumsy looking) code that turns a postcode into an output I'm happy with. See below.
library("PKI") #make a character string of the post code in 8 character format x<-"GG22 1WD" #get it into a string of numbers y<-raw2hex((charToRaw(x)),sep="") #make a 16 digit pin for the key, in this case with a simple set of sequential numbers pin<-as.raw(1:16) #make a encryption key mykey<-AES(pin,mode="ECB") #encrypt the postcode z<-mykey$encrypt(y) #finally convert this to a manageable string pccrypt<-raw2hex(z,sep="") #summary of the outputs x y z pccrypt Now, I’ve got a couple of questions about this Firstly and most importantly if I have a data.frame where one of my columns contains these postcodes (e.g. df below) how can I run this workflow (or something slicker, that does the same thing) and put the result into a column in the data.frame? I’ve tried making a function and I’ve tried some of the plyr commands, but been unable to do achieve this. Secondly there seem to be a lot of steps to get the text string into a format that the AES command can use, is there a way to make this simpler? #make a simple data.frame with some sample codes postcode<-c("AB5 2TG","B1 8AA","TG22 4XB") df<-as.data.frame(postcode) df Any help gratefully received. GavinR ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.