An 8- and 12-bit block AES cipher

Peter T. Breuer · 2025

Read An 8- and 12-bit block AES cipher by Peter T. Breuer (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2508-18485.txt.

Introduction

Peter Breuer documents a tiny version of the AES cipher. It works on blocks of just eight and twelve bits. Java source code comes with it. AES, also called Rijndael, normally uses much larger blocks. A tiny variant is unusual and hard to find in print. The piece is an exposition, not a research study. It offers a teaching scale model of the famous cipher. At this size, readers can follow each step by hand. They can also run the code and inspect what it does.

Catalog record

CREATORPeter T. Breuer
YEAR2025
COLLECTIONPAPERS
FORMATTXT
FILE SIZE48 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2508-18485

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

An 8- and 12-bit block AES cipher Peter T. Breuer Abstract Abstract Because it is so unusual, or hard to find, or expository, a truly tiny 8- or 12-bit block AES (Rijndael) cipher is documented here, along with Java source code. 1 Introduction The intent here is to document a simple 8- or 12-bit (or more) block AES (Rijndael) cipher [ 3 ] . The small numbers make for a very clear exposition. AES ciphers are standardly of much larger block-size than 8 or 12 bits, with 128 bits or more being typical, but small block-sizes can still be useful in combination with appropriate padding of the plaintext and frequent changes of key. My own difficulty in producing a small AES cipher for use in encrypted computing [ 1 ] lay with the unfortunate circumstance that I had no cryptographic knowledge at all and could not find any implementation code for the right block-size on the Web. So I reverse-engineered those AES source codes that I could find, generating an understanding of the principles in the process – well enough to create my own tiny version of the cipher. The source code that helped me most (other codes I found were too sophisticated) came in a set of files called ’simple_aes.c’, ‘ecb_decrypt.c’, ‘simple_aes_decr.c’, ‘ecb_encrypt.c’, without any indicator of authorship, but I believe from associated hints and a memory of my original search that the files came from the Cambridge University Computer Lab. There is certainly a great deal of expertise evident in that source code – things are done clearly and simply, which is a hard trick to pull off if one is not an expert. The 12-bit block cipher will be described first below, out of no particular prejudice, and then the few changes that the 8-bit block cipher requires will be described. A Java source code implementation for the 8-bit block cipher will be set out too (and an Appendix to the text here has it verbatim). 2 The 12-bit cipher The idea of the AES cipher is simple – do a sequence of 1-1 operations in an appropriate space, the parameters of each operation in the sequence being set by the secret key. To decrypt, run the same sequence of 1-1 operations in reverse. The ‘appropriate space’ here is a space of 4-dimensional (‘4D’) vectors. Each of the four ordinates are numbers in the range 0-7, i.e. a 3-bit binary number. That means that the cipher works with 4 \times 3=12-bit plaintext, converting it to a 12-bit ciphertext. That is a 12-bit block cipher. Later we will also look at a 4 \times 2=8-bit design. Each 3-bit ordinate lives in a special arithmetic field, a so-called GF(8) field of numbers 0-7 which when written out as three binary bits a_{2}a_{1}a_{0} can be taken as the coefficients of a polymomial a_{2}x^{2}+a_{1}x+a_{0} ‘over’ the field of modulo 2 arithmetic, which means that the coefficients are mod 2, and are added and multiplied mod 2 when required. Polynomials are added and multiplied in the usual way polynomials are multiplied, subject to (i) the coefficients are mod 2, and (ii) x is a root of a certain irreducible cubic polynomial p(x) , so p(x)=0 . A typical 3-bit ordinate is 101, or x^{2}+1 , being 1 times x^{2} plus 0 times x^{1} plus 1 times x^{0} . I choose to set p(x)=x^{3}+x+1 , so that x^{3}+x+1=0 . The equation allows powers of 3 and higher of x to be expressed in terms of the powers of 2 and lower. That is x^{3}=x+1 , since the coefficients are taken modulo 2. One can be sure that my choice of p(x) is irreducible over this field, because if it were to factor at least one of the factors would be linear (since the order of p is 3, so the factors must have order 2 and 1, or 1 and 1 and 1). A linear factor is of the form x-K , where K is in the underlying modulo 2 arithmetic field, hence 0 or 1. So 0 or 1 would be a root of p . But p(0)=1 and p(1)=1+1+1=1 , so neither is a root. Hence p is indeed irreducible. In this setting, 3+2=1 because that is 011 and 010 added bitwise to give 001 mod 2. And 3*2, i.e., 011*010, is calculated by multiplying 0x^{2}+x+1 by 0x^{2}+x+0 , giving x^{2}+x , or 110, i.e. 6, as expected. But 3*4, i.e., 011*100, is calculated multiplying 0x^{2}+x+1 by x^{2} , giving x^{3}+x^{2} , or x+1+x^{2} , i.e., 111. Thus 3*4=7. The reason for choosing GF(8) rather than, say, simple addition and multiplication modulo 8 on the numbers 0-7, is that multiplication mod 8 has non-zero divisors of zero, so that 4*2=0, for example. So there cannot be a division operation mod 8. In contrast, GF(8) is a field and every non-zero number has a multiplicative inverse in it. Being a field, one can make a matrix with entries in the field, and hope to be able to invert the matrix provided its determinant is non-zero. Nevertheless, there might be viable alternatives to a GF( 2^{n} ) field in the construction here, particularly when n=2^{m} . I am thinking of the power- 2^{2^{m}} fragments of Conway’s On 2 field [ 2 ] . This is the sequence of 1-1 operations that the cipher performs on the 4D vector \bar{x} with 3-bit ordinates in the range 0-7: 1. add a constant 4D vector \bar{K}_{1} : \bar{x}\mapsto\bar{x}+\bar{K}_{1} 2. apply a constant 1-1 permutation S of 0-7 in-place on each ordinate: {(x_{1},x_{2},x_{3},x_{4})}\mapsto(S(x_{1}),S(x_{2}),S(x_{3}),S(x_{4})) 3. apply a constant permutation \pi to the ordinates: {(x_{1},x_{2},x_{3},x_{4})}\mapsto(x_{\pi(1)},x_{\pi(2)},x_{\pi(3)},x_{\pi(4)}) 4. apply a constant invertible 4D matrix transformation M : \bar{x}\mapsto M\bar{x} 5. add a constant 4D vector \bar{K}_{2} : \bar{x}\mapsto\bar{x}+\bar{K}_{2} 6. apply the constant 1-1 permutation S of 0-7 in-place on each ordinate again: {(x_{1},x_{2},x_{3},x_{4})}\mapsto(S(x_{1}),S(x_{2}),S(x_{3}),S(x_{4})) 7. apply the constant permutation \pi to the ordinates again: {(x_{1},x_{2},x_{3},x_{4})}\mapsto(x_{\pi(1)},x_{\pi(2)},x_{\pi(3)},x_{\pi(4)}) 8. add a constant 4D vector \bar{K}_{3} : \bar{x}\mapsto\bar{x}+\bar{K}_{3} The decryption operation does these operations in reverse, thus: 1. subtract the constant 4D vector \bar{K}_{3} : \bar{x}\mapsto\bar{x}-\bar{K}_{3} 2. apply the constant permutation \pi^{-1} to the ordinates : {(x_{1},x_{2},x_{3},x_{4})}\mapsto(x_{\pi^{-1}(1)},x_{\pi^{-1}(2)},x_{\pi^{-1}(3)},x_{\pi^{-1}(4)}) 3. apply the constant 1-1 permutation S^{-1} in-place on each ordinate: {(x_{1},x_{2},x_{3},x_{4})}\mapsto(S^{-1}(x_{1}),S^{-1}(x_{2}),S^{-1}(x_{3}),S^{-1}(x_{4}) 4. subtract the constant 4D vector \bar{K}_{2} : \bar{x}\mapsto\bar{x}-\bar{K}_{2} 5. apply the constant 4D matrix transformation M^{-1} : \bar{x}\mapsto M^{-1}\bar{x} 6. apply a constant permutation \pi^{-1} to the ordinates: {(x_{1},x_{2},x_{3},x_{4})}\mapsto(x_{\pi^{-1}(1)},x_{\pi^{-1}(2)},x_{\pi^{-1}(3)},x_{\pi^{-1}(4)}) 7. apply the constant 1-1 substitution S^{-1} in-place on each ordinate: {(x_{1},x_{2},x_{3},x_{4})}\mapsto(S^{-1}(x_{1}),S^{-1}(x_{2}),S^{-1}(x_{3}),S^{-1}(x_{4})) 8. subtract the constant 4D vector \bar{K}_{1} : \bar{x}\mapsto\bar{x}-\bar{K}_{1} With this design, encryption and decryption are guaranteed to be mutually inverse operations. One may note that the transformation is really A_{1};S^{4};A_{2};S^{4};A_{3} where A_{1} , A_{2} , A_{3} are affine transformations on the 4D vector space, and S^{4} is the permutation S of the field elements applied in place to each of the four ordinates. The vectors \bar{K}_{1} , \bar{K}_{2} , \bar{K}_{3} , are derived from a single 12-bit input key. They are called ‘round keys’, and change as the input key is changed. The permutations S , \pi and the matrix M are constant, selected beforehand and coded statically into the algorithm. For the permutation S of 0-7, I chose one that factors into two

Read the complete text