Documentation
¶
Overview ¶
Package mentalpoker implements the cryptographic core of a dealerless card shuffle ("mental poker"): a commutative cipher that lets two players jointly shuffle and deal a deck so that neither player — nor the blind relay — learns the deck order or the other's hand, yet every card can be revealed and verified at showdown.
Scheme (Pohlig–Hellman / SRA over a safe prime). p is a 2048-bit safe prime (RFC 3526 group 14); q=(p-1)/2 is prime and the quadratic residues mod p form the unique subgroup of order q. Each card i is encoded as a distinct QR token_i. A player's secret is an exponent k in [2,q-1]; encryption is c = m^k mod p and decryption c^(k⁻¹ mod q) mod p. Because the subgroup has prime order q every k is invertible mod q, and exponentiation commutes, so
Eₐ(E_b(m)) = m^(kₐ·k_b) = E_b(Eₐ(m)).
To deal a doubly-encrypted card m^(kₐk_b) to A, B strips its layer (Decrypt_b → m^kₐ) and A strips its own (Decrypt_a → m); B never sees m because it would need kₐ. Cheating is caught at showdown: both players reveal their exponents and anyone (including spectators) recomputes the shuffle and checks the fully-decrypted deck is exactly the 52 tokens — see VerifyDeck.
Index ¶
- Constants
- func Decode(m *big.Int) int
- func EncryptAll(key Key, deck []*big.Int) []*big.Int
- func FreshDeck() []*big.Int
- func Marshal(deck []*big.Int) [][]byte
- func Shuffle(deck []*big.Int) error
- func Token(i int) *big.Int
- func Unmarshal(raw [][]byte) []*big.Int
- func VerifyDeck(deck []*big.Int, a, b Key) bool
- type Key
Constants ¶
const DeckSize = 52
DeckSize is a standard 52-card deck.
Variables ¶
This section is empty.
Functions ¶
func EncryptAll ¶
EncryptAll returns a new deck with every card raised to key (order preserved).
Types ¶
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key is a player's secret exponent and its inverse mod q.
func KeyFromExponent ¶
KeyFromExponent reconstructs a key from a revealed exponent (for showdown verification). Returns ok=false if the exponent isn't a valid unit mod q.