Hiding messages in a deck playing cards

https://news.ycombinator.com/rss Hits: 8
Summary

hiding messages in playing cardsI was recently thinking about the huge number of ways you can shuffle a deck of 52 cards and wondered if it would be possible to store arbitrary data, which I explore in this blog post.This blog post will go into the detail of how I found a way to store text inside the order of a deck of cards. If you want to play around with the tool, go here. How many different ways can we shuffle a deck of 52 cards? We can think of it like picking one card from 52, then one from the remaining 51, and so on. We would get an expression that looks like (52)⋅(52−1)⋅(52−2)⋅...⋅(52−51)(52)\cdot(52-1)\cdot(52-2)\cdot...\cdot(52-51)(52)⋅(52−1)⋅(52−2)⋅...⋅(52−51), which is the same as the factorial of 52, which is shown as 52!52!52!. If we evaluate 52!52!52! we get around 8⋅10678 \cdot 10^{67}8⋅1067. This tells us that the number of bits that can be represented by a deck of cards is ⌊log2(8⋅1067)⌋\left\lfloor log_2(8 \cdot 10^{67}) \right\rfloor⌊log2​(8⋅1067)⌋, or 225225225 bits. But how do we actually store arbitrary bits? We need a one-to one mapping between the order of the cards and the theoretically usable bits. Initial thinking made me believe it could be done by using the color of the cards, because a deck of 52 cards will have 26 black cards and 26 red cards, however that would, in a worst-case scenario, only give you 262626 bits, only 11.5˙11.\dot511.5˙% of our theoretical limit. I later came across the concept of a Lehmer code, which allows you to numerically represent each unique permutation of set of elements. The easiest way to compute a Lehmer code is to make each element have its own number or id, and then for each element we count the number of elements to the right of it that are less than it. An animation of this process is below.Another way to generate a lehmer code is to make a list of all the numbers you have, and for each number, find the index of the number of your list and then remove it. This is not as fast as the first method but i...

First seen: 2025-07-21 16:37

Last seen: 2025-07-21 23:40