Store Text in a Deck of Cards

in #software7 years ago (edited)

Store text/emoji in decks of cards!

Giger Tarot

Currently, these decks are supported:

NameDescriptionStorage capacity
poker52 cards28 bytes
skat32 cards14 bytes
quartettA1 to H414 bytes
tarot0 to XXI8 bytes

How to use

I wrote a Ruby Script for this. Just download it to your home folder, open a terminal and start it like this:

$ ruby cardfs.rb encode "Looks like it worked! 😀"
Encoded "Looks like it worked! 😀":
6c Td Qs Js 3s 4d 9h Ks 2h Jh 7h 3c 5h Qc 7s As 3h 8s 8c Jc 2s Kh 7c 5s 9d Qd Ah 8d Jd 2c 9c 3d 5d 8h 6s 6h 5c 9s Qh 4h 4c Th 4s Ad 2d 6d 7d Kd Ts Ac Tc Kc

Entropy is Information

Chaos is information, order is not. If we put the word “entropy” in a poker deck we can see this on the left side of the deck:

CardFS

Do you see "entropy" on the left side of the deck? The right side is still ordered which means that it contains no information, but on the left side, some cards look shuffled. That's where the information is.

Digital is digital is digital

Every form of digital information can be encoded as any other form. Text is digital. The order of cards in a deck is digital. This means we can encode text as order of cards, if we find the right path. The path I took takes three steps:

Text to bytes

Bytes are ordered groups of 8 bits each. Luckily, somebody already came up with a way to store any text as bytes: UTF-8. Done!

bytes to one big number

Since big numbers when stored in a computer are just a bunch of bits anyway we can just take all the bits from all the bytes of the text and concatenate them to form one big number. I chose to do this in little endian so the bits of the first byte go into the least significant bits of the big number. Example:

First byte:  10101010 (170)
Second byte: 11110000 (240)

Big number:  1111000010101010 (61610)

Big number to card stack permutation

If we use a poker deck, the first card in the deck will be one of 52 cards. We choose the card by numbering the cards from 0 to 51, then divide the big number by 52 and take the remainder (modulo) as the card number to pick for the first card. Since one card is already used up the second card will be one out of only 51 so we number the remaining cards from 0 to 50, divide the big number by 52 first and then take the remainder of dividing that by 51 to get the next card number. We continue this until all cards are chosen.

Bits in cards

Information is measured in how surprising it is: In a deck of 32 cards, the last card will carry 0 bits of information (because when you reach it you already know which one it is because you saw all other 31 cards), but the first card will carry 5 bits and the second one only 4.95; each new cards actually has more bits than the previous card, which is the reason why a deck of 52 cards has twice as much bytes without having twice as much cards compared to the 32 cards deck.

Thus, the least information fits in the Tarot deck which only contains 22 cards and thus only holds 8 bytes of information. The deck arrangement at the start of this post has maximum entropy but contains only a short text. Can you read what it says? Try ruby cardfs.rb decode --deck tarot xx xvii... if you can't do it in your head ;)

Sort:  

Hi steemiren

Fallow me then send a massage

I will give you a good upvote

And

I invite you to join us

https://c3k93.app.goo.gl/i/J5psE

🎋

Do I get some special reward for decoding..... (SPOILER ALERT.....) Bad Omen..?
Very interesting post, indeed. Not so useful, but interesting! :D