Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Decipher a string using the affine cipher
| ResourceFunction["AffineDecipher"][string,{a,b}] deciphers string using the affine cipher with parameters a and b. | |
| ResourceFunction["AffineDecipher"][{a,b}] represents an operator form of ResourceFunction["AffineDecipher"] that can be applied to an expression. | 

Convert a simple text:
| In[1]:= | ![ResourceFunction["AffineDecipher"]["ihhwvc swfrcp", {5, 8}]](https://www.wolframcloud.com/obj/resourcesystem/images/5b4/5b46ede4-a0ad-4f0a-a0dd-a176e1ffe034/73137f0068bf71cd.png) | 
| Out[1]= |  | 
AffineDecipher automatically maps over a list of strings:
| In[2]:= | ![ResourceFunction[
 "AffineDecipher"][{"zrwu", "wu", "i", "zcuz"}, {5, 8}]](https://www.wolframcloud.com/obj/resourcesystem/images/5b4/5b46ede4-a0ad-4f0a-a0dd-a176e1ffe034/6ba615c1f72c5f68.png) | 
| Out[2]= |  | 
Create an operator:
| In[3]:= | ![op = ResourceFunction["AffineDecipher"][{5, 8}]](https://www.wolframcloud.com/obj/resourcesystem/images/5b4/5b46ede4-a0ad-4f0a-a0dd-a176e1ffe034/5cbb7cae8338b8df.png) | 
| Out[3]= |  | 
Apply the operator to a string:
| In[4]:= | ![op["nillaav"]](https://www.wolframcloud.com/obj/resourcesystem/images/5b4/5b46ede4-a0ad-4f0a-a0dd-a176e1ffe034/4af3b835fa258a48.png) | 
| Out[4]= |  | 
The Caesar decipher can be recreated using the affine decipher by choosing a=1:
| In[5]:= | ![string = "Bpqa qa rcab i bmab";
{ResourceFunction["AffineDecipher"][string, {1, 8}], ResourceFunction["CaesarDecipher"][string, 8]}](https://www.wolframcloud.com/obj/resourcesystem/images/5b4/5b46ede4-a0ad-4f0a-a0dd-a176e1ffe034/4a2ea33b4bdef078.png) | 
| Out[5]= |  | 
AffineDecipher could be recast in terms of the resource function AffineCipher:
| In[6]:= | ![enciphered = "ihhwvc swfrcp";
deciphered = ResourceFunction["AffineDecipher"][enciphered, {5, 8}]](https://www.wolframcloud.com/obj/resourcesystem/images/5b4/5b46ede4-a0ad-4f0a-a0dd-a176e1ffe034/77dcc60056cbc172.png) | 
| Out[6]= |  | 
Again decipher, this time using AffineCipher with appropriate parameter values for inverting:
| In[7]:= | ![minv = ModularInverse[5, 26];
ResourceFunction["AffineCipher"][enciphered, {minv, -8 minv}]](https://www.wolframcloud.com/obj/resourcesystem/images/5b4/5b46ede4-a0ad-4f0a-a0dd-a176e1ffe034/6e1a70bd8e8d4fb8.png) | 
| Out[7]= |  | 
The parameter a must be coprime to 26:
| In[8]:= | ![ResourceFunction["AffineDecipher"]["vlyetg mzbvjly", {14, 11}]](https://www.wolframcloud.com/obj/resourcesystem/images/5b4/5b46ede4-a0ad-4f0a-a0dd-a176e1ffe034/5fc3050e02f8f292.png) | 
| Out[8]= |  | 
Some of the permissible values for a are:
| In[9]:= | ![Select[Range[100], CoprimeQ[#, 26] &]](https://www.wolframcloud.com/obj/resourcesystem/images/5b4/5b46ede4-a0ad-4f0a-a0dd-a176e1ffe034/059a94df11103d75.png) | 
| Out[9]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License