Last active
February 18, 2022 01:27
-
-
Save atoponce/a927f8074756e85f919291019b5c60f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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