summaryrefslogtreecommitdiffstats
path: root/zsh/oh-my-zsh/plugins/genpass/genpass-xkcd
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-03-25 16:43:09 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-03-25 16:43:09 +0530
commita62114c91f2070c8c8453d117f3d81dc113e41ff (patch)
treef266e87af29a08c01f82bc32dd7d463d8ec4441a /zsh/oh-my-zsh/plugins/genpass/genpass-xkcd
parentaf120ab348f2e1a5a39dec035ed9dcf84189a64e (diff)
downloaddotfiles-a62114c91f2070c8c8453d117f3d81dc113e41ff.tar.gz
dotfiles-a62114c91f2070c8c8453d117f3d81dc113e41ff.tar.bz2
dotfiles-a62114c91f2070c8c8453d117f3d81dc113e41ff.zip
dotfile update
Diffstat (limited to 'zsh/oh-my-zsh/plugins/genpass/genpass-xkcd')
-rwxr-xr-xzsh/oh-my-zsh/plugins/genpass/genpass-xkcd68
1 files changed, 0 insertions, 68 deletions
diff --git a/zsh/oh-my-zsh/plugins/genpass/genpass-xkcd b/zsh/oh-my-zsh/plugins/genpass/genpass-xkcd
deleted file mode 100755
index ed03971..0000000
--- a/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
-} </dev/urandom