-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
each diceware word list consists of lines of words. each word is prefixed (exception of the rule: diceware8k) with a "dicechain", a string which represents the result of a dice throw: '1' when the dice shows '1', a '5' when the dice shows a '5' and so on. the used word lists are compiled into words_xyz.go. because each list is roughly 80/90kbyte in size, my initial plan was to gzip the raw lists, base64 it again and use this internally. the result was something in the ballpark of 50kbyte, but the lists could not be checked visually anymore. by removing the prefix the lists shrink to ~50kbyte and can be checked visually. the prefix for each position in the list can be calculated by transforming the index from base-10 to base-6 ('0'-'5') and adjusting the shown value by '1' ('0' becomes '1', '5' becomes '6' etc). to convert a "dicechain" of the user to an index in the word list, the values are first decreased by 1 ('6' becomes '5' etc) and then converting a base-6 number to base-10: dicechain base10 11111 <-> 0000 11112 <-> 0001 11116 <-> 0005 12345 <-> 0310 54321 <-> 5910 66666 <-> 7775
- Loading branch information
Showing
13 changed files
with
55,033 additions
and
11,866 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// a (chain of) dice rolls (lets say "dicechain") result in a string like | ||
// "12345" (the first throw was a '1', the second one a '2' etc.). | ||
// | ||
// a diceware list essentially is a list of words, prefixed with a dice roll | ||
// chain: | ||
// | ||
// 11111 a | ||
// 11112 a&p | ||
// 11113 a's | ||
// 11114 aa | ||
// 11115 aaa | ||
// 11116 aaaa | ||
// | ||
// so, '11111' maps to index '0', '11116' maps to index '6' in the list. | ||
// | ||
// by using (real world) dices, a user creates a dicechain, look up the | ||
// word in the list, repeat. the -electronic mode switches to the weaker | ||
// (from a quality of randomness point of view) (pseudo-) random number | ||
// generator of the operating system, picks the word of the used list | ||
// based upon the random number, repeat. | ||
// | ||
// i removed the dicechain prefix of each list to slim down the size of | ||
// each list. | ||
|
||
// parse a dicechain into an "index". | ||
func parseDiceChain(chain string) (int, error) { | ||
|
||
if len(chain) != 5 { | ||
return -1, fmt.Errorf("invalid dicechain %q: expected 6 chars", chain) | ||
} | ||
|
||
r := strings.Map(diceDown, chain) | ||
n, err := strconv.ParseInt(r, 6, 32) | ||
|
||
return int(n), err | ||
} | ||
|
||
func indexToDiceChain(index int) string { | ||
|
||
r := strconv.FormatInt(int64(index), 6) | ||
r = fmt.Sprintf("%05s", r) | ||
return strings.Map(diceUp, r) | ||
} | ||
|
||
func diceDown(r rune) rune { | ||
|
||
switch r { | ||
case '1': | ||
return '0' | ||
case '2': | ||
return '1' | ||
case '3': | ||
return '2' | ||
case '4': | ||
return '3' | ||
case '5': | ||
return '4' | ||
case '6': | ||
return '5' | ||
} | ||
|
||
panic("unhandled rune " + string(r)) | ||
|
||
return 0 | ||
} | ||
|
||
func diceUp(r rune) rune { | ||
|
||
switch r { | ||
case '0': | ||
return '1' | ||
case '1': | ||
return '2' | ||
case '2': | ||
return '3' | ||
case '3': | ||
return '4' | ||
case '4': | ||
return '5' | ||
case '5': | ||
return '6' | ||
} | ||
|
||
panic("unhandled rune " + string(r)) | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.