Ludo dice checker

Before the first roll, Ludo - The Clean One picks a secret key that decides every roll of the game, and shows its fingerprint. After the game it reveals the key. This page recomputes every roll from the key with code that is not part of the game, so you don't have to trust the game's own check.

In the game: after a game, tap Check the dice, then Share the rolls. The link it shares fills this page in. Nothing you enter here is sent anywhere; the check runs in your browser.

Digits 1 to 6. Spaces, commas and line breaks are ignored.

How the rolls are made

The secret key is 32 random bytes. Its fingerprint is the SHA-256 hash of those bytes, written in hex. Roll number i (counting from 0, every player's rolls in the order they happened) is worked out like this:

  1. Hash the key followed by i and a round number r (starting at 0), each as 4 bytes, most significant byte first: SHA-256(key || i || r).
  2. Take the first byte of the hash that is below 252, and the roll is that byte mod 6, plus 1. Using only bytes below 252 (6 × 42) keeps every face exactly equally likely.
  3. If no byte is below 252 (it almost never happens), add 1 to r and hash again.

The same in a few lines of Python, if you'd rather check with your own code:

import hashlib

def roll(key_hex, i):
    key = bytes.fromhex(key_hex)
    r = 0
    while True:
        h = hashlib.sha256(key + i.to_bytes(4, "big") + r.to_bytes(4, "big")).digest()
        for b in h:
            if b < 252:
                return b % 6 + 1
        r += 1

def check(fingerprint, key_hex, rolls):
    assert hashlib.sha256(bytes.fromhex(key_hex)).hexdigest() == fingerprint.lower()
    assert all(roll(key_hex, i) == int(d) for i, d in enumerate(rolls))

Because the fingerprint is shown before the first roll, the key can't be swapped for a different one during the game: no other key has the same fingerprint.

Fishtail Apps