5D Library › Dream Motif Bipartite Graphs, Deterministic Oracle Decks and Subconscious Prior Activation · 中文

Chapter 4. Avalanche, Collisions and How Unique a Reading Is

One changed character, a new reading

A good hash function has the avalanche property: changing one bit of the input flips each output bit with probability one half (National Institute of Standards and Technology 2015). For a hashed oracle this has a plain consequence. Asking “Should I launch the course now?” and then the same words with a full stop instead of a question mark gives two unrelated readings; so does asking the same question one day later.

Calculation

# Chapter 4. p07: Avalanche - how much one changed character moves the
# reading. For 20,000 users the question "Should I launch the course
# now?" is compared with the same words ending in "." instead of "?",
# and with the same question asked one day later. Seed and shuffle as in
# p05. Reported: the share of the 256 seed bits that flip, and how often
# the top card or the whole three-card spread stays the same, against
# the 1/54 and 1/148,824 expected of independent readings.
import hashlib
import statistics

DECK = ["{}{:02d}".format(s, r) for s in "FWAE" for r in range(1, 14)]
DECK += ["JK1", "JK2"]

def seed_of(user, date, question):
    q = hashlib.sha256(question.encode("utf-8")).hexdigest()
    return hashlib.sha256("{}|{}|{}".format(user, date, q)
                          .encode("utf-8")).digest()

def spread(seed, k=3):
    deck, i, buf = list(DECK), 0, b""
    for n in range(len(deck) - 1, 0, -1):
        limit = (2 ** 32 // (n + 1)) * (n + 1)
        while True:
            if not buf:
                buf = hashlib.sha256(seed + i.to_bytes(4, "big")).digest()
                i += 1
            w, buf = int.from_bytes(buf[:4], "big"), buf[4:]
            if w < limit:
                break
        j = w % (n + 1)
        deck[n], deck[j] = deck[j], deck[n]
    return tuple(deck[:k])

def flipped(a, b):
    return bin(int.from_bytes(a, "big") ^ int.from_bytes(b, "big")) \
        .count("1") / 256

if __name__ == "__main__":
    n, q = 20000, "Should I launch the course now?"
    for label, alt in (("'?' -> '.'", lambda u: (u, "2026-11-09",
                                                  q[:-1] + ".")),
                       ("next day", lambda u: (u, "2026-11-10", q))):
        fl, top, three = [], 0, 0
        for k in range(n):
            u = "u{:05d}".format(k)
            a, b = seed_of(u, "2026-11-09", q), seed_of(*alt(u))
            fl.append(flipped(a, b))
            sa, sb = spread(a), spread(b)
            top += sa[0] == sb[0]
            three += sa == sb
        print("   {:10s}: bits flipped {:.3f} (sd {:.3f}); same top card "
              "{} of {:,}".format(label, statistics.mean(fl),
                                  statistics.pstdev(fl), top, n))
        print("               same spread {}; expected {:.1f} and {:.3f}"
              .format(three, n / 54, n / 148824))
#    '?' -> '.': bits flipped 0.500 (sd 0.031); same top card 349 of 20,000
#                same spread 0; expected 370.4 and 0.134
#    next day  : bits flipped 0.500 (sd 0.031); same top card 378 of 20,000
#                same spread 0; expected 370.4 and 0.134

Changing the final “?” to “.” flips 0.500 of the 256 seed bits on average (sd 0.031). Across 20,000 users the top card stayed the same 349 times and the whole spread never, against 370.4 and 0.134 expected of two independent readings. Asking a day later: 378 same top cards, no same spread. The reading tracks the bytes of the question, not its meaning. That is exactly what makes it fair and checkable, and exactly why it cannot “understand” the question: a reader who rephrases until the cards look right is drawing again.

How unique is “your” reading?

The birthday problem gives the number of users at which two of them probably share a reading. With NN equally likely readings, the chance that nn users all differ is ∏i<n(1−i/N)\prod_{i<n}(1 – i/N), and a repeat becomes more likely than not at about 2Nln⁡2\sqrt{2N\ln 2} users.

Calculation

# Chapter 4. p08: Birthday bounds - how unique is "your" reading?
# For N equally likely readings, the smallest number of users n with a
# 50% chance that two of them get the same one is found exactly from
# P(no repeat) = prod (1 - i/N); the approximation sqrt(2 N ln 2) is in
# brackets.
# Readings: one card (54), a three-card spread (148,824), a 7-day path
# of one card a day drawn with replacement (54**7), the full order (54!).
# Also: expected pairs sharing a spread among 10,000 users in one day.
import math

def n50(N, cap=5000000):
    p, n = 1.0, 1
    while n < cap:
        p *= 1 - n / N
        n += 1
        if p <= 0.5:
            return n
    return None

if __name__ == "__main__":
    cases = (("one card", 54), ("3-card spread", 54 * 53 * 52),
             ("7-day path", 54 ** 7), ("full order", math.factorial(54)))
    for name, N in cases:
        approx = math.sqrt(2 * N * math.log(2))
        exact = n50(N) if N < 10 ** 13 else None
        print("   {:13s} N = {:.4g}: 50% repeat at n = {} ({:.4g})"
              .format(name, N, "{:,}".format(exact) if exact else "-",
                      approx))
    users = 10000
    pairs = users * (users - 1) / 2 / 148824
    print("   10,000 users in a day: expected pairs with the same spread "
          "{:.1f}".format(pairs))
    share = 1 - (1 - 1 / 148824) ** (users - 1)
    print("   chance a given user shares the spread with someone: {:.3f}"
          .format(share))
#    one card      N = 54: 50% repeat at n = 9 (8.652)
#    3-card spread N = 1.488e+05: 50% repeat at n = 455 (454.2)
#    7-day path    N = 1.339e+12: 50% repeat at n = 1,362,405 (1.362e+06)
#    full order    N = 2.308e+71: 50% repeat at n = - (5.657e+35)
#    10,000 users in a day: expected pairs with the same spread 335.9
#    chance a given user shares the spread with someone: 0.065

For a single card, 9 users suffice for an even chance of a repeat. For an ordered three-card spread (148,824 possibilities), 455 users. For a 7-day path of one card a day drawn with replacement, 1,362,405 users. Only the full order of the deck is out of reach of any user base. In a single day with 10,000 users, about 335.9 pairs of users receive the identical spread, and any given user has a 0.065 chance of sharing his or her spread with someone. A reading can be personal in the sense of being computed from the user’s own inputs while being shared with hundreds of strangers.

Note

Collisions are not a fault. A collision does not mean that the hash is weak; it is arithmetic about how many distinct readings exist. A service that tells each user the reading is “unique to you” should either use readings with far more possibilities than users, or not say so.

Summary

One changed character or one day’s difference flips half the seed bits and gives an unrelated reading. With 148,824 spreads, 455 users have an even chance of a repeat, and 10,000 users a day produce about 335.9 pairs with identical spreads.

References

National Institute of Standards and Technology. 2015. Secure Hash Standard (SHS). Federal Information Processing Standards Publication 180-4.

Fan, Y. (2026). Dream Motif Bipartite Graphs, Deterministic Oracle Decks and Subconscious Prior Activation: REM Semantic Spreading, SHA-256 Fisher-Yates Permutations and Retroactive Coincidence Rates [梦境意象二分图、确定性哈希牌卡与潜意识先验激活] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090233 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).