## Encryption assignment template
# Complete the definitions of the 'encrypt' and 'decrypt' functions using the one time pad algorithm,
# and generating a psudorandom key. 
# Hint: use functions like rawToBits, charToRaw, packBits, intToBits, xor

encrypt <- function(input) {
    if (class(input) != "character"){
        stop("Expected character input")
    }
    # This function should return an encrypted string, and the key used to encrypt it
    list(string=input, key = NA)
}

decrypt <- function(input_list) {
    # Check if we're getting a list
    if (class(input_list) != "list") {
        stop("Expected list")
    }
    # Check if we have the inputs we need
    if (!("string" %in% names(input_list)) || !("key" %in% names(input_list))){
       stop("Need both the encrypted string and the key")   
    }
    # Should now return the encrypted string
    return(input_list$string)
}

my_message <- "Encryption is neat, but this isn't it."
encrypted <- encrypt(my_message)
decrypted <- decrypt(encrypted)

if (my_message != decrypted){
    stop("Decryption doesn't match")
}
if (encrypted$string == my_message){
    warning("This code doesn't appear to be doing any actual encrypting...")
}
