Hayrat Games

How to check a deal

In an online game of Bahraini Kout, nobody, not even our server, can change the cards once they are dealt without it showing. This page explains how, and how to check it yourself.

The idea

  1. Before each deal, the server picks a seed: 32 random bytes. The seed alone decides how the cards are shuffled.
  2. When it deals, the server sends every player the seed’s fingerprint, its SHA-256 hash. The fingerprint gives nothing away about the cards.
  3. After the game, the server reveals every seed. “Check the deals” on the game-over screen compares each one with its fingerprint and rebuilds your hand from it.

Finding a different seed with the same fingerprint is practically impossible, so a seed that matches its fingerprint is the one chosen before anyone saw a card.

Checking it yourself

Copy the seeds and fingerprints from “Check the deals” (Copy all). Then, for each deal at a table of 4:

  1. Read the seed as 32 bytes (it is written as 64 hex digits). Its SHA-256 hash, in lower-case hex, must equal the deal’s fingerprint.
  2. Start from the deck in its fixed order: spades, hearts, clubs, diamonds, each from 7 up to ace, without the 7 of diamonds; then the joker. That is 32 cards, in positions 0 to 31.
  3. Make a stream of numbers from the seed: the SHA-256 hash of the seed followed by a 4-byte counter (big-endian, starting at 0, then 1, 2 …). Each hash gives eight 32-bit numbers, read big-endian.
  4. Shuffle: for each position i from 31 down to 1, take the next number w. If w is below 2³² − (2³² mod (i+1)), let j = w mod (i+1); otherwise skip w and take the next one. Swap the cards at positions i and j.
  5. Deal: 8 cards at a time from the top of the shuffled deck, first to the player on the dealer’s right, then on round the table counter-clockwise. Your 8 cards must match the hand you were dealt.

Redeals count too: a deal where everyone passed has its own seed and fingerprint.

A test value

For a seed of 32 zero bytes, the fingerprint is the value below, and the shuffled deck begins J♣ A♦ K♣ Q♥ A♣ K♦ J♦ 9♠. If your own check gives the same, it follows the method.

66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925

What it doesn’t prove

The fingerprint proves a deal wasn’t changed after it was published. It can’t prove how the seed was chosen in the first place: it comes from a secure random source on our server. Letting the players add to the seed would close that gap, and we may add it later.