edgecase
War never changes, but weapons do.
Author: StJohn Piano
Published: 2018-11-13
Datafeed Article 67
586 words - 148 lines - 4 pages

Parts

- Description
- Assets
- Notes
- Recipe

Description

This recipe describes a method of using dice to generate entropy bytes.

Assets

Description: A script that converts dice roll results into bytes.
convert_dice_rolls_to_hex_bytes_2.py [paywalled]

Notes

Using this recipe to generate 32 bytes of entropy (enough for a Bitcoin private key) should take about 10 minutes.

Suggestions:
- Rolling the dice on a flat tray with raised edges stops them from scattering too far.
- Listening to music can make the dice rolling quite tolerable.
- 5 dice is a convenient number of dice to roll repeatedly.
- Roll 5 dice at a time, record 5 dice rolls per line, and separate groups of 5 lines with an extra newline. Each group will then consist of 25 dice rolls, making it straightforward to calculate the total number of dice rolls.

This recipe was originally published in the article Generating entropy with dice. Please read the linked article for more information about the development of the recipe, the algorithm behind it, its disadvantages, and suggestions for further work. The recipe shown here has been edited for republication.

The code used in this recipe was developed under Python 2.7.13 running on Mac OS X 10.6.8 (Snow Leopard), and should run successfully on other versions of Python 2.7.

The asset
convert_dice_rolls_to_hex_bytes_2.py
1) supersedes the previous version
convert_dice_rolls_to_hex_bytes.py
which is stored with the article Generating entropy with dice.
2) is originally an asset of the article Using a transaction to validate a Bitcoin address. Please read the Downloadable Assets section of the linked article for details concerning the changes in the new version.

Recipe

1) Obtain one or more dice.

2) Choose a desired number of bytes of entropy. Multiply this number by 8 to convert to bits. Divide the result by the expected-bit-rate-per-dice-roll value (1.3333) to find the expected number of dice rolls that should generate this number of entropy bits. Multiply this result by 1.1 to add a 10% margin, then round up to the nearest integer.

Note: Some dice roll result values will be discarded so that the value domain becomes base4, which can be then be converted to base16 (i.e. hex bytes). About 66% of the entropy will be preserved.

3) Perform this number of dice rolls and record the results in a text file. An individual dice roll must be recorded as one individual character from the list "123456". Whitespace (newline, tab, space) can be used to separate groups of dice roll values.

4) In the script convert_dice_rolls_to_hex_bytes_2.py, scroll to the section of text that lies between
##### START CONTROLS

and
##### END CONTROLS

- Set the variable
desired_n
to be the desired number of bytes of entropy.
- Set the variable
dice_rolls_file_path
to be the path to the text file containing the dice roll results.

5) Open a terminal. Change directory to the directory containing this script. Run the script using the following command:
python convert_dice_rolls_to_hex_bytes_2.py

6) The output of the script should contain the generated entropy as hex bytes.

7) (optional) If more dice rolls are needed in order to reach the desired number of bytes of entropy, the script will calculate a suggested number of new dice rolls. Perform the dice rolls, add the results to the dice roll results text file, and run the script again.