X-Git-Url: https://src.twobees.de/?a=blobdiff_plain;f=stow%2Foh-my-zsh%2F.oh-my-zsh%2Fplugins%2Fgenpass%2Fgenpass-xkcd;fp=stow%2Foh-my-zsh%2F.oh-my-zsh%2Fplugins%2Fgenpass%2Fgenpass-xkcd;h=0000000000000000000000000000000000000000;hb=1a8e170bbe5c6641a26ab1ce2e6ce6c5c1faa4cd;hp=ed0397138e6c0fd489bd23af4681b8af8628f790;hpb=475ba35502579302593f4735c853c49ef1845dcb;p=dotfiles.git diff --git a/stow/oh-my-zsh/.oh-my-zsh/plugins/genpass/genpass-xkcd b/stow/oh-my-zsh/.oh-my-zsh/plugins/genpass/genpass-xkcd deleted file mode 100755 index ed03971..0000000 --- a/stow/oh-my-zsh/.oh-my-zsh/plugins/genpass/genpass-xkcd +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env zsh -# -# Usage: genpass-xkcd [NUM] -# -# Generate a password made of words from /usr/share/dict/words -# with the security margin of at least 128 bits. -# -# Example password: 9-mien-flood-Patti-buxom-dozes-ickier-pay-ailed-Foster -# -# If given a numerical argument, generate that many passwords. -# -# The name of this utility is a reference to https://xkcd.com/936/. - -emulate -L zsh -o no_unset -o warn_create_global -o warn_nested_var -o extended_glob - -if [[ ARGC -gt 1 || ${1-1} != ${~:-<1-$((16#7FFFFFFF))>} ]]; then - print -ru2 -- "usage: $0 [NUM]" - return 1 -fi - -zmodload zsh/system zsh/mathfunc || return - -local -r dict=/usr/share/dict/words - -if [[ ! -e $dict ]]; then - print -ru2 -- "$0: file not found: $dict" - return 1 -fi - -# Read all dictionary words and leave only those made of 1-6 characters. -local -a words -words=(${(M)${(f)"$(<$dict)"}:#[a-zA-Z](#c1,6)}) || return - -if (( $#words < 2 )); then - print -ru2 -- "$0: not enough suitable words in $dict" - return 1 -fi - -if (( $#words > 16#7FFFFFFF )); then - print -ru2 -- "$0: too many words in $dict" - return 1 -fi - -# Figure out how many words we need for 128 bits of security margin. -# Each word adds log2($#words) bits. -local -i n=$((ceil(128. / (log($#words) / log(2))))) - -{ - local c - repeat ${1-1}; do - print -rn -- $n - repeat $n; do - while true; do - # Generate a random number in [0, 2**31). - local -i rnd=0 - repeat 4; do - sysread -s1 c || return - (( rnd = (~(1 << 23) & rnd) << 8 | #c )) - done - # Avoid bias towards words in the beginning of the list. - (( rnd < 16#7FFFFFFF / $#words * $#words )) || continue - print -rn -- -$words[rnd%$#words+1] - break - done - done - print - done -}