Function Repository Resource:

# AffineCipher

Encipher a string using the affine cipher

Contributed by: Sander Huisman
 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.

## Details and Options

For the affine cipher, the letters "a"–"z" are numbered 0–25. Each character in string is converted to a number x using the aforementioned numbering. Each number is then transformed by computing (ax+b)mod26. The new numbers are then reinterpreted as letters.
Here is an example enciphering the letters "A"–"Z" for a=5 and b=8. Deciphering is done by reading the diagram from bottom to top.
The case of the letters is retained by ResourceFunction["AffineCipher"].

## Examples

### Basic Examples (1)

Convert a simple text:

 In[1]:=
 Out[1]=

### Scope (2)

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]=

### Properties and Relations (1)

The Caesar cipher can be recreated using the affine cipher by choosing a=1:

 In[5]:=
 Out[5]=

### Possible Issues (2)

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]=

SHuisman

## Version History

• 1.0.0 – 07 August 2019