Cryptography for Everybody: The ASCII Enigma – An Enigma Machine with 256-Pin Rotors

Recently, I created the “TextAES”, an AES-like cipher, where each building block of the original AES was replaced by a classical cipher. Of course, I also made a video about that and uploaded it onto my YouTube channel 🙂

After getting some feedback on my corresponding blog article here, I created the ASCII Enigma. An Enigma machine with 256-pin rotors. The basic idea was to create an Enigma machine that resembles the original design, but allows the encryption of more then the standard 26 Latin characters.

Three new Enigmas

In total, I developed three different new Enigmas and programmed these in C#: the Morse Enigma, the Enigma64, and the ASCII Enigma.

The Morse Enigma allows the encryption of more than 26 letters, but it still only uses symbols, that can be sent using Morse code. The main idea was, that this machine could have been built in the 1940s and Morse code was the state-of-the-art transmission media for messages. This Enigma machine has rotors with 38 pins. It allows the encryption of the letters A-Z, digits 0-9, and four special characters ( . , ! ? ).

The next Enima is the Enigma64. It allows the encryption of uppercase letters A-Z, lowercase letters a-z, digits 0-9, and two special characters ( . , ). My idea here is, that the created ciphertexts can still be represented using printable characters. By replacing . and , with / and +, the machine could easily by converted to a “Base64 Enigma”.

The last and most powerful Enigma I created is the ASCII Enigma. It allows the encryption of all 256 ASCII symbols. Since a lot of these are not printable, the resulting ciphertexts should be either converted to Base64, Hex values, or just stored in a binary file.

The C# Code

My C# code does not only allow to create these “fantasy” Enigmas, but also to create original Enigmas. I implemented the Enigma 1 for testing my code. Finally, one can also create Enigmas with only 1 or even 1,000 rotors. It can be easily done using only a few C# statements. Below you see how to create an Enigma 1:

int[] key = new int[] { 0, 1, 2 }; // A B C <--> we work on numbers instead of letters

//create plugboard with three plugs
int[][] plugs = new int[3][];
plugs[0] = new int[] { 0, 1 }; // plug A <-> B
plugs[1] = new int[] { 2, 3 }; // plug C <-> D
plugs[2] = new int[] { 4, 5 }; // plug E <-> F

//create rotors for machine
Rotor rotor1 = new Rotor(MapTextIntoNumberSpace(Enigma1.RotorI, Alphabets.Alphabet26), Enigma1.RotorINotches, 0);
Rotor rotor2 = new Rotor(MapTextIntoNumberSpace(Enigma1.RotorII, Alphabets.Alphabet26), Enigma1.RotorIINotches, 0);
Rotor rotor3 = new Rotor(MapTextIntoNumberSpace(Enigma1.RotorIII, Alphabets.Alphabet26), Enigma1.RotorIIINotches, 0);
Rotor reflector = new Rotor(MapTextIntoNumberSpace(Enigma1.UKWA, Alphabets.Alphabet26), null, 0);

//create machine
RotorMachine enigma1 = new RotorMachine(new Rotor[] { rotor1, rotor2, rotor3 }, reflector, new Plugboard(Alphabets.Alphabet26, plugs), Alphabets.Alphabet26);

//reset machine key
enigma1.Key = key;

//plaintext:
string text = "HELLOXWORLDXTHISXISXAXTESTXTEXT";
Console.WriteLine(text);

//encrypt/decrypt and print all to console
int[] plaintext = MapTextIntoNumberSpace(text, Alphabets.Alphabet26);
int[] ciphertext = enigma1.CryptText(plaintext);
Console.WriteLine(MapNumbersIntoTextSpace(ciphertext, Alphabets.Alphabet26));

//reset machine key
enigma1.Key = key;

int[] decrypted = enigma1.CryptText(ciphertext);
Console.WriteLine(MapNumbersIntoTextSpace(decrypted, Alphabets.Alphabet26));

Here, we create an Enigma 1 with three rotors (I, II, III), a plugboard, and the reflector UKWA. My implementation does not take the “rings” into account since these are cryptographically irrelevant. And it eased the code :-). If you want to have an implemention of the Enigma with rings, have a look at CrypTool 2.

My YouTube Video and the Source Code

Of couse, I also made a video about the ASCII Enigma:

I Created an Enigma Machine with 256-Pin Rotors – The ASCII Enigma

If you are interested in getting your hands on the source code, I created a GitHub project where you can get it from: https://github.com/n1k0m0/ASCIIEnigma

Cryptography for everybody: I Created a Text-Based AES-Like Cipher – A Cipher Built Using Only Classical Ciphers

Can you build a cipher with the structure of the Advanced Encryption Standard (AES), our current standard modern symmetric cipher, but only use classical ciphers? I asked myself this question when I implemented AES in C# as a preparation for my upcoming AES videos on my YouTube channel in 2021.

AES’ structure (10 rounds for AES-128) consists of 4 different building blocks:
1) AddRoundKey,
2) SubBytes,
3) ShiftRows, and
4) MixColumns:

AES structure

The AddRoundKey building block adds a round key to the state array of 16 bytes (or plain and/or ciphertext) using XOR. The SubBytes building block substitutes each byte using AES’ S-Box, the ShiftRows building block performs a shift of the rows of the state array, and the MixColumns building block mixes the columns of the state array by multiplying each “vector” with an invertible matrix in the finite field GF(2^8).

When I implemented each of these four steps, I was reminded of some classical ciphers: AddRoundKey reminded me of an additive cipher, SubBytes reminded me of a simple substitution cipher, MixColumns reminded me of a transposition cipher, and the matrix multiplication finally reminded me of a Hill cipher.

Thus, I changed the inputs (plaintext and key) and the output (ciphertext) of the AES to simple text (just letters from A to Z), exchanged AddRoundKey with an additive cipher (using MOD 26), exchanged SubBytes by SubBigrams (a bigram substitution cipher), I kept ShiftRows as it was, and exchanged MixColumns with a 4×4 Hillcipher (also using MOD 26). The “TextAES” was born :-).

To also allow decryption, I computed the inverse S-Box (an inverse lookup table for the bigram substitution cipher) and an inverse matrix for the Hill cipher.

I kept the key expansion more or less as it was, but with text, and also used the bigram substitution and replaced its round constants by “AAAA”,”BAAA”,”CAAA”, etc.

Finally, I was convinced that you can create an AES-like cipher using only classical ciphers :-).

If you are interested in details of this self-made crazy cipher, have a look at the video I made about it:

I Created a Text-Based AES-Like Cipher

If you are interested in details of the real AES, you may also have a look at my other two videos about AES and AES key schedule:

AES – The Advanced Encryption Standard Explained
AES – Key Schedule/Key Expansion Explained

Also, if you want to play with my source code in C# of AES and TextAES, you can find it freely available on GitHub: https://github.com/n1k0m0/AES-and-Text-Based-AES

Finally, here is the original publication of AES:
Daemen, Joan, and Vincent Rijmen. The design of Rijndael. Vol. 2. New York: Springer-verlag, 2002.

Nils