Creating randomness in p2p applications

Bitpoker.io
Bitpoker.io
Published in
2 min readAug 2, 2017

--

The correct use of pure randomness is very important cryptography and games such as poker. We must be sure the deck has been shuffled correctly. The client has the ability to use a hardware random number generator, TrueRNG and c++ / windows drivers have been added to the GitHub repo.

For those who are not using a hardware random number generator, the solution uses the Bouncy Castle secure random number generator.

That being said, how do we make sure the deck is shuffled and the contents can not be “peaked” or altered? The terminology is called Mental Poker and is described in the BitPoker readme.

An algorithm for shuffling cards using commutative encryption would be as follows:

  1. Alice and Bob agree on a certain “deck” of cards. In practice, this means they agree on a set of numbers or other data such that each element of the set represents a card.
  2. Alice picks an encryption key A and uses this to encrypt each card of the deck.
  3. Alice shuffles the cards.
  4. Alice passes the encrypted and shuffled deck to Bob. With the encryption in place, Bob cannot know which card is which.
  5. Bob picks an encryption key B and uses this to encrypt each card of the encrypted and shuffled deck.
  6. Bob shuffles the deck.
  7. Bob passes the double encrypted and shuffled deck back to Alice.
  8. Alice decrypts each card using her key A. This still leaves Bob’s encryption in place though so she cannot know which card is which.
  9. Alice picks one encryption key for each card (A1, A2, etc.) and encrypts them individually.
  10. Alice passes the deck to Bob.
  11. Bob decrypts each card using his key B. This still leaves Alice’s individual encryption in place though so he cannot know which card is which.
  12. Bob picks one encryption key for each card (B1, B2, etc.) and encrypts them individually.
  13. Bob passes the deck back to Alice.
  14. Alice publishes the deck for everyone playing (in this case only Alice and Bob, see below on expansion though).

The deck is now shuffled!

In future build, we will also add entropy via the ANU Quantum Random Numbers Server

--

--