Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Perform Vigenère's substitution cipher on a string
ResourceFunction["VigenereCipher"][string,key] enciphers string using the key key. | |
ResourceFunction["VigenereCipher"][string,{key1,key2,…}] repeatedly enciphers string using first key1, then key2, etc. | |
ResourceFunction["VigenereCipher"][{s1,s2,…},key] enciphers the strings s1,s2, etc. using the key key. | |
ResourceFunction["VigenereCipher"][key] represents an operator form of ResourceFunction["VigenereCipher"] that can be applied to an expression. |
Encipher a message using the key "LEMON":
In[1]:= |
Out[1]= |
Encipher with multiple keys:
In[2]:= |
Out[2]= |
Encipher a message twice, first using "GO" and then "CAT":
In[3]:= |
Out[3]= |
Encipher multiple strings:
In[4]:= |
Out[4]= |
Create an operator that enciphers strings with the key "sparks":
In[5]:= |
Out[5]= |
Apply the operator to a string:
In[6]:= |
Out[6]= |
If a single character is used, the Vigenère cipher is identical to the Caesar cipher:
In[7]:= |
Out[7]= |
When enciphering with multiple keys, the keys can first be enciphered with each other to encipher the message with a single key. The length of the replacing key has to be the LCM of the lengths of each of the keys:
In[8]:= |
Out[8]= |
This indeed matches with what you expect:
In[9]:= |
Out[9]= |
The case of the original text is retained; the case of the key does not matter:
In[10]:= |
Out[10]= |
In[11]:= |
Out[11]= |
Spaces and the letters "a" and "A" in the key will not alter the original message:
In[12]:= |
Out[12]= |
The key should have valid letters and valid length:
In[13]:= |
Out[13]= |
In[14]:= |
Out[14]= |
In[15]:= |
Out[15]= |
Two keys can "negate" each other:
In[16]:= |
Out[16]= |
Enciphering the keys with each other gives a string with only “A”s:
In[17]:= |
Out[17]= |
Spaces, numbers and letters outside the regular English alphabet are not transformed:
In[18]:= |
Out[18]= |
Use RemoveDiacritics, StringDelete, IntegerName and ToLowerCase to transform the message:
In[19]:= |
Out[19]= |
Enciphering the transformed message results in a much-harder-to-crack cipher:
In[20]:= |
Out[20]= |
This work is licensed under a Creative Commons Attribution 4.0 International License