I read a paper titled "On the entropy of LEGO", which explains how to calculate the number of ways to combine $n$ $b\times w$ LEGO blocks of the same color. For example, six $2\times4$ bricks have $915103765$ ways to combine. I wonder if could we construct a funny cipher algorithm using LEGO bricks.

Some definitions and symbols:

A $2\times4$ brick $i$ can be defined as: $b_i:=\left( \begin{array}{cc} s_0,s_1,s_2,s_3 \\ s_4,s_5,s_6,s_7 \end{array} \right)$, where $s_{i,k}:=(0/1,-/b_j)$ means if a stud $s_{i,k}$ is occupied by another brick $b_j$, then $s_{i,k}=(1,b_j)$; else if no brick is put on this stud $s_{i,k}$, then $s_{i,k}=(0,-)$.

Then, we have a key space $\mathcal{K}=\{b_1\cup b_2\cup ...\cup b_n\}$, where $n$ is the number of bricks, $\cup$ means the combination of bricks (Sorry, I cannot find an appropriate symbol to present the meaning).

The number $num$ of ways to combine $n$ $2\times4$ bricks is: $num:=(2^{n-1} + 46^{n-1})/2$, therefore, the size of $\mathcal{K}$ is the number $num=|\mathcal{K}|$.

Assuming that there is an one way function $f(k,m)\to c,k\in\mathcal{K}, m\in\mathcal{M},c\in\mathcal{C}$, where $\mathcal{M}$ is the plaintext space, and $\mathcal{C}$ is the ciphertext space.

So far, I still cannot find a method to construct the one-way function and confirm whether the LEGO bricks can be used to construct a cipher algorithm or not.

  • 2
    $\begingroup$ I'm sure we can construct one with LEGO bricks. See Solitaire which is constructed from playing cards. If nothing else you could make playing cards from LEGO and then run Solitaire. Or treat green bricks as 1 and red bricks as 0 and then run AES. $\endgroup$ Commented Nov 2, 2021 at 10:05
  • 3
    $\begingroup$ You can build any of the standard logic gates with LEGO, which can be combined to make encryption hardware. $\endgroup$
    – dan04
    Commented Nov 2, 2021 at 18:41
  • 1
    $\begingroup$ Back in 1977, Desmond Bagley's novel The Enemy had a subplot of using trucks on a computerized model railway to encode messages. Compared to that, Lego bricks is pretty straightforward. $\endgroup$
    – Graham
    Commented Nov 2, 2021 at 22:25

2 Answers 2


It seems like what you are actually describing is a way to encode data with Lego bricks, rather than encrypting with them. But, maybe the way that you encode data is hard to invert without knowing a secret key, for example.

I don't think the lego adds security to this encoding, though. Suppose you design a method $f$ to encode your message space $\mathcal{M}$ into possible arrangements of bricks, $\mathcal{B}$. I could design my own correspondence $g$ between bitstrings $\{0,1\}^n$ and $\mathcal{B}$ (for some $n$). Then $g^{-1}\circ f$ maps from $\mathcal{M}$ into $\{0,1\}^n$, turning your lego cipher into a regular cipher on bitstrings. This means that if you encrypt a message into bricks and I find the bricks, I can translate their arrangement into bricks and attack the cipher as though it were a traditional computer cipher. Hence, if your map from messages into brick arrangements is supposed to be secure, it should also be secure when viewed as a map from messages into bitstrings.

From this I think the hard work of designing a normal secure cipher still needs to be done, even if lego is the end goal. But I can still see two uses of lego: (1) steganography: to store a small encrypted message in a way that most people wouldn't notice is important; (2) to help compute a cipher by hand (e.g., by making parts of the "computation" easy to store and move around).


It is possible to build something reminiscent of mechanical cipher machines using Lego Technic gears and less complicated parts:

Perhaps https://bricks.stackexchange.com/ would be a better place to ask about implementation.

It's also possible to write messages (or store a secret key) using LEGO bricks, although that's generally considered "encoding" rather than "encrypting". Perhaps this could be used as a kind of steganography.

(The Legos mentioned in "Fully homomorphic encryption: Introduction and bootstrapping" are more metaphorical).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.