Skip to content

Instantly share code, notes, and snippets.

@atoponce
Last active February 18, 2022 01:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atoponce/a927f8074756e85f919291019b5c60f7 to your computer and use it in GitHub Desktop.
Save atoponce/a927f8074756e85f919291019b5c60f7 to your computer and use it in GitHub Desktop.
collect-entropy () {
zmodload zsh/mathfunc
local wordlist=($(grep -P '^[aoeuidhtns]{3,}$' /usr/share/dict/words))
local length=${#wordlist[@]}
local min=$(( 65536 % $length ))
local wordcount=$(( int(ceil(512/log2($length))) ))
local words=()
for ((i=1; i<=${wordcount}; i++ )) do
local rand=$(( 0x$(xxd -ps -l 2 /dev/urandom) ))
until [[ $rand -ge $min ]]
do
rand=$(( 0x$(xxd -ps -l 2 /dev/urandom) ))
done
words+=(${wordlist[$(( ($rand % $length) + 1 ))]})
done
printf "Type, not copy/paste these ${wordcount} words in the event tester window.\n"
printf "Move your mouse a bit in the event tester window afterward if desired.\n"
printf "Close the event tester window when finished.\n"
printf "\n"
printf "$words\n" | fold -s
local entropy=$(strace --timestamps=precision:ns xev 2>&1)
printf "\n\n"
printf "Here is your entropy: "
printf %s "${entropy}" | gzip -c | b2sum | awk '{print $1}'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment