Hi-lo guide
Tsunami Hi-lo: an exercise in checking cards yourself
The page is called Tsunami only because that was its original slug; the hi-lo here has no special features. Rather than describing verification, the page sets an exercise: compute three cards from given seeds on your own computer, then compare with the answer key at the bottom.
What you need
- A computer with Python 3 installed. No extra packages are needed; hashlib and hmac are part of the standard library.
- The practice inputs below. They are made up for this exercise and belong to no real service.
- About ten minutes.
The practice inputs
- Revealed server seed
tsunami-practice-seed-93- Commitment that was shown in advance
e3ea6f2072c86b8c3bc135adbf5c58179a269b24cdb7ac1014cd6e0cf3eb2c1a- Client seed
my-own-seed- Nonces to check
- 0, 1 and 2
Steps
- Hash the server seed with SHA-256 and print it as hex. Compare it character by character with the commitment above. If it differs at all, the rest of the exercise is pointless.
- For nonce 0, build the text
my-own-seed:0:0(client seed, nonce, round number). - Compute HMAC-SHA256 with the server seed as the key and that text as the message.
- Take the first 8 hex digits, convert them to an integer, and divide by 4,294,967,296 (that is 2^32).
- Multiply by 13, round down, add 1. Write down the rank.
- Repeat steps 2 to 5 for nonces 1 and 2.
import hashlib, hmac
server = "tsunami-practice-seed-93"
client = "my-own-seed"
print(hashlib.sha256(server.encode()).hexdigest())
for nonce in range(3):
msg = f"{client}:{nonce}:0".encode()
d = hmac.new(server.encode(), msg, hashlib.sha256).hexdigest()
u = int(d[:8], 16) / 2**32
print(nonce, d[:8], u, int(u * 13) + 1)
The script mirrors the steps. Type it rather than pasting it if you want to be sure you understand each line. Note that int(u * 13) rounds down for positive numbers, which is all that is needed here.
Answer key
| Nonce | First 8 hex | Float | Rank |
|---|---|---|---|
| 0 | 922f8ca9 | 0.57103805 | 8 |
| 1 | b804df8e | 0.71882436 | 10 |
| 2 | 0566fc6c | 0.02110269 | 1 |
Computed with Python's hmac and hashlib. Floats are rounded to 8 decimals for display.
If your answer differs
- Check for a stray space or newline in the seeds. Hashes change completely with any extra character.
- Check the separator. This exercise uses colons; a service might use something else.
- Check that the key is the server seed and the message is the client text, not the other way round.
- Check that you read 8 hex digits (4 bytes), not 8 bytes.
Taking it further
Once the three ranks match, apply calls to them. If nonce 0 is the face card and the call is higher, nonce 1 decides it. Working through a few rounds by hand shows that verification confirms the cards; it never changes the expected loss built into the payouts.