# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Decipher a Vigenère-enciphered string

Contributed by:
Sander Huisman

ResourceFunction["VigenereDecipher"][ deciphers | |

ResourceFunction["VigenereDecipher"][ repeatedly deciphers | |

ResourceFunction["VigenereDecipher"][{ deciphers the strings | |

ResourceFunction["VigenereDecipher"][ represents an operator form of ResourceFunction["VigenereDecipher"] that can be applied to an expression. |

The key can be in either lowercase or uppercase letters.

Spaces in the key will leave letters unchanged, as do the letters "A" and "a" in the key.

Letters outside "a"–"z" and "A"–"Z" are not transformed.

The case of the enciphered message is retained in the deciphered message.

When multiple keys are given and the LCM of the lengths of the keys is small, the keys get combined into a single key, which is then used to decipher *string*. This will, especially for long strings, yield faster results and give the same result as Fold[ResourceFunction["VigenereDecipher"],*string*,{*key*_{1},*key*_{2},…}].

ResourceFunction["VigenereDecipher"][*key*][*string*] is equivalent to ResourceFunction["VigenereDecipher"][*string*,*key*].

Decipher a message using the key "LEMON":

In[1]:= |

Out[1]= |

Decipher with multiple keys:

In[2]:= |

Out[2]= |

Decipher a message twice, first using "GO" and then with "CAT":

In[3]:= |

Out[3]= |

Decipher multiple strings:

In[4]:= |

Out[4]= |

Create an operator that deciphers 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 a Caesar cipher:

In[7]:= |

Out[7]= |

When deciphering with multiple keys, the keys can first be enciphered with each other to decipher 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]= |

VigenereDecipher is related to the resource function VigenereCipher:

In[12]:= |

Out[12]= |

Spaces and the letters "a" and "A" in the key will not alter the enciphered message:

In[13]:= |

Out[13]= |

The key should have valid letters and valid length:

In[14]:= |

Out[14]= |

In[15]:= |

Out[15]= |

In[16]:= |

Out[16]= |

Two keys can "negate" each other:

In[17]:= |

Out[17]= |

Enciphering the keys with each other gives a string with only "A"s:

In[18]:= |

Out[18]= |

- 1.0.0 – 14 June 2019

This work is licensed under a Creative Commons Attribution 4.0 International License