Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Performs Caesar’s substitution cipher on a string
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. |
The letter c is converted to the letter f.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]= |
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]= |
Cipher a message:
| In[7]:= |
| Out[7]= |
Decipher a message:
| In[8]:= |
| Out[8]= |
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]= |
Characters with diacritics are ignored:
| In[14]:= |
| Out[14]= |
Use RemoveDiacritics to convert these letters to unaccented letters:
| In[15]:= |
| Out[15]= |
Figure out what long English words are still English words after being Caesar-ciphered:
| In[16]:= | ![]() |
| Out[17]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License