mardi 17 mai 2016

Having trouble with CRAN doc's crypto example and gam::random

I'm trying to follow along with the examples given in CRAN's cryptography vignette but funnily enough one of the functions used therein seems to be breaking:

# Encrypt message using random one-time-pad
msg <- charToRaw("TTIP is evil")
one_time_pad <- random(length(msg))
ciphertext <- base::xor(msg, one_time_pad)

# It's really encrypted
rawToChar(ciphertext)

Which should return "(8\xd7ȉ%\u035f\x81\xbb\023\xa2" but instead line one_time_pad <- random(length(msg)) throws the error

Error in random(xvar = length(msg)) : 
  random() expects a factor or category as its first argument

Which makes it difficult to get to the next step of

# Decrypt with same pad
rawToChar(base::xor(ciphertext, one_time_pad))
# should return
# [1] "TTIP is evil"

Any ideas on what I'm doing wrong / different from the CRAN doc?

NOTE: I'm assuming the gam library needs to be loaded and I'm using

> version
               _                           
platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          3                           
minor          2.2                         
year           2015                        
month          08                          
day            14                          
svn rev        69053                       
language       R                           
version.string R version 3.2.2 (2015-08-14)
nickname       Fire Safety 




Aucun commentaire:

Enregistrer un commentaire