if you want "A B" to be processible, then you need a solution that can scramble at a minimum 262+1 characters, not just 262 characters I think.
The easiest way to address is to add space to your list of letters and process 27 instead of 26.
or you could come up with a solution where you record the position of every space in the input and put them back in after scrambling. but this extra code solution is so easy ...
Caesar = function(input){
answer = ""
solution = NULL
Low = "abcdefghijklmnopqrstuvwxyz "
Up = "ABCDEFGHIJKLMNOPQRSTUVWXYZ "
Lower = strsplit(Low,"")
Lower = Lower[[1]]
Upper = strsplit(Up, "")
Upper = Upper[[1]]
cutI = strsplit(input,"")
cutI = unlist(cutI)
df_Result = data.frame(n.Kan = 1:27)
for(n in 1:27){
answer = ""
for (i in cutI){
if (i %in% ""){
answer = paste0(collapse = "")
} else if (i %in% Lower){
ind = which(Lower == i)
indN = (as.numeric(ind)+n)%%27
if(indN %% 27==0){
indN = 27
}
answer = paste0(c(answer, Lower[indN]),collapse="")
} else{
ind = which(Upper == i)
indN = (as.numeric(ind)+n)%%27
if(indN%%27==0){
indN = 27
}
answer = paste0(c(answer, Upper[indN]), collapse = "")
}
answer=paste0(answer, collapse="")
}
solution = c(solution,answer)
}
df_Result = cbind(df_Result , "Result" = solution)
return(df_Result)
}