Shift Cipher:

In the shift cipher, each character is represented by
a number and then a fixed number (the key) is added to all the characters to form
the cipher text. For simplicity, we remove all spaces and punctuation from
the text and assume that every character is a lower case letter. This can be accomplished
by the ToLowerCase command.

We will convert a string to its character code and then add the constant number to
it and then convert is back to the character code.

In[10]:=

  ToCharacterCode[ "abcdefghijklmnopqrstuvwxyz"]

Out[10]

We see that the codes are consecutive. This will make the computation simpler.
If we subtract 97 from the code, and then add number modulo 26, then add 97 to the number
and convert it back to a string, then we will have the cipher text. This is done in the
following procedure.

In[11]:=

  shiftcipher[ s_, k_]:= Module[ {s1},
                           s1=StringReplace[
                               ToLowerCase[s], { " "->""}];
                           l=ToCharacterCode[ s1]-97;
                            l=Mod[ l+k,26];
                            s1=FromCharacterCode[l+97];
                            Return[s1]]
    

In[12]:=

  shiftcipher[ "abc",3]

Out[12]

In[13]:=

   shiftcipher[ "I came I saw I conquered", 7]

Out[13]

The string should have no punctuation other than spaces. If you want to allow punctuation, then
the StringReplace command in the procedure needs to modified appropriately. Since
conversion of a string to numeric form is common, we will write a separate function for this.

In[14]:=

  ToNumericForm[m_String]:= Module[ {text},
                text=ToLowerCase[m];
                If[Length[StringPosition[text," "]]>=1,
                text= StringReplace[text," "->""]];
                text=ToCharacterCode[text]-97;
                Return[text]]
                 
                

Out[14]

In[15]:=

  ToNumericForm[ "GHIJKLM "]

Out[15]


We also need the inverse of this operation, to convert a list of numbers modulo 26 to
the string form.

In[16]:=

  ToTextForm[ plain_List]:=FromCharacterCode[plain+97]

Up to String Manipulation