Function Repository Resource:

ChaoCipher

Source Notebook

Encipher a string using the Chaocipher

Contributed by: Sander Huisman

ResourceFunction["ChaoCipher"][string,{αp,αp}]

enciphers string using the plain text alphabet αp and the cipher alphabet αc.

Details and Options

The alphabets αp and αc should be a permutation of the letters "A"–"Z".
Any other letter than "a"–"z" and "A"–"Z" in string is ignored.
The output is in capital letters.
ResourceFunction["ChaoCipher"] works by encoding each character in string using the following steps ("MATHEMATICA" will be used as the input string throughout this example):
The character "M" is looked up in the plain alphabet (top). One finds the corresponding letter "A" in the cipher alphabet (bottom), so "M" is encoded to "A""
Both alphabets are shifted to the left such as to bring the red letters to the front:
The plain alphabet (top) is shifted one more to the left:
Move the 3rd letter of the plain alphabet (top) and the 2nd letter of the cipher alphabet (bottom) to the 14th position:
Continue with the next letter using the new alphabets:

Examples

Basic Examples (2) 

Encipher a piece of text using unshuffled plain and cipher alphabets:

In[1]:=
ResourceFunction[
 "ChaoCipher"]["HELLO WORLD", {CharacterRange["a", "z"], CharacterRange["a", "z"]}]
Out[1]=

Encode a "constant" string:

In[2]:=
ResourceFunction[
 "ChaoCipher"]["AAAAAAAAAAAAAAAAAAAAAA", {CharacterRange["a", "z"], CharacterRange["a", "z"]}]
Out[2]=

Scope (1) 

Use random plain and cipher alphabets:

In[3]:=
pa = {"L", "Z", "G", "U", "Q", "A", "X", "B", "J", "R", "T", "F", "D",
    "K", "E", "N", "Y", "P", "S", "O", "C", "M", "W", "I", "H", "V"};
ca = {"G", "W", "Z", "J", "P", "Q", "V", "R", "D", "C", "H", "X", "S",
    "U", "T", "K", "M", "E", "O", "F", "Y", "A", "I", "L", "N", "B"};
encoded = ResourceFunction["ChaoCipher"]["Mathematica is awesome", {pa, ca}]
Out[3]=

Properties and Relations (2) 

The resource function ChaoDecipher can be used to reverse the encryption. First encode a piece of string with ChaoCipher:

In[4]:=
pa = "PTLNBQDEOYSFAVZKGJRIHWXUMC" // Characters;
ca = "HXUCZVAMDSLKPEFJRIGTWOBNYQ" // Characters;
encoded = ResourceFunction["ChaoCipher"][
  "WELLDONEISBETTERTHANWELLSAID", {pa, ca}]
Out[4]=

Now we can decipher it with the resource function ChaoDecipher:

In[5]:=
ResourceFunction["ChaoDecipher"][encoded, {pa, ca}]
Out[5]=

Possible Issues (2) 

Letters with diacritics are ignored:

In[6]:=
ResourceFunction[
 "ChaoCipher"]["piñata", {CharacterRange["a", "z"], CharacterRange["a", "z"]}]
Out[6]=

Use RemoveDiacritics to remove the diacritics:

In[7]:=
ResourceFunction["ChaoCipher"][
 RemoveDiacritics["piñata"], {CharacterRange["a", "z"], CharacterRange["a", "z"]}]
Out[7]=

Publisher

SHuisman

Version History

  • 1.0.0 – 01 August 2019

Source Metadata

Related Resources

License Information