Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Encipher a string using the affine cipher
ResourceFunction["AffineCipher"][string,{a,b}] enciphers string using the affine cipher with parameters a and b. | |
ResourceFunction["AffineCipher"][{a,b}] represents an operator form of ResourceFunction["AffineCipher"] that can be applied to an expression. |
Convert a simple text:
In[1]:= | ![]() |
Out[1]= | ![]() |
AffineCipher automatically threads over a list of strings:
In[2]:= | ![]() |
Out[2]= | ![]() |
Create an operator:
In[3]:= | ![]() |
Out[3]= | ![]() |
Apply the operator to a string:
In[4]:= | ![]() |
Out[4]= | ![]() |
The Caesar cipher can be recreated using the affine cipher by choosing a=1:
In[5]:= | ![]() |
Out[5]= | ![]() |
The parameter a must be coprime with 26:
In[6]:= | ![]() |
Out[6]= | ![]() |
Some of the permissible values for a are:
In[7]:= | ![]() |
Out[7]= | ![]() |
Strings using numbers or letters with diacritics are not converted:
In[8]:= | ![]() |
Out[8]= | ![]() |
Use RemoveDiacritics, StringDelete, IntegerName and ToLowerCase to transform the message:
In[9]:= | ![]() |
Out[9]= | ![]() |
Now the transformed message can be enciphered:
In[10]:= | ![]() |
Out[10]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License