Rotate every letter in string by K places
if the only thing you need to encrypt in the string are the letters, you can be more concise by using only one loop doing something like:

if c &gt;= 'a' &amp;&amp; c &lt;= 'z' {
    a = (((c-'a')+K)%26)+'a'
} else if c&gt;= 'A' &amp;&amp; c &lt;= 'Z' {
    a = (((c-'A')+K)%26)+'A'
} else {
    a = c
}


with c being the char from the original string and a the char to add to the encrypted string.