Function Repository Resource:

# CaesarCipher

Performs Caesar’s substitution cipher on a string

Contributed by: Sander Huisman
 ResourceFunction["CaesarCipher"][string,n] shifts every letter in string by n places further in the Latin alphabet. ResourceFunction["CaesarCipher"][{s1,s2,…},n] shifts every letter of each of the strings s1,s2, … by n places in the Latin alphabet.

## Details and Options

The Caesar cipher replaces each plain text character with a different one a fixed number of places n down the alphabet. As an example here we show it for n=3:  The letter c is converted to the letter f.
ResourceFunction["CaesarCipher"][string] performs the ROT13 substitution cipher.
n can be negative, shifting the letters to the left.
CaesarCipher lists over the first argument.
Letters retain their case (lowercase/uppercase).

## Examples

### Basic Examples

Perform a Caesar cipher with a shift of 2:

 In[1]:=
 Out[1]=

Decipher a text by shifting the letters 9 positions back:

 In[2]:=
 Out[2]=

### Scope

Cipher/decipher using a shift of n=13, also known at the ROT13 cipher:

 In[3]:=
 Out[3]=
 In[4]:=
 Out[4]=

Cipher multiple strings:

 In[5]:=
 Out[5]=

If the shift is an integer multiple of 26 the Caesar cipher does not affect the input string:

 In[6]:=
 Out[6]=

### Applications

Cipher a message:

 In[7]:=
 Out[7]=

Decipher a message:

 In[8]:=
 Out[8]=

### Properties and Relations

Deciphering can be done using the same function but with a negative shift:

 In[9]:=
 Out[9]=

Manually do a cipher:

 In[10]:=
 Out[11]=

Replace the characters of a string:

 In[12]:=
 Out[12]=

CaesarCipher gives the same output:

 In[13]:=
 Out[13]=

### Possible Issues

Characters with diacritics are ignored:

 In[14]:=
 Out[14]=

Use RemoveDiacritics to convert these letters to unaccented letters:

 In[15]:=
 Out[15]=

### Neat Examples

Figure out what long English words are still English words after being Caesar-ciphered:

 In[16]:=
 Out[17]=