commit 0388c85624241671417e938ef8f227ec3bde6851
parent c31c225d619e436ab674e72f50cb8ed62a32acae
Author: boredpasta <boredpasta@tutanota.com>
Date: Wed, 12 Mar 2025 21:18:45 +0200
add some stuff
Diffstat:
A | badphrase | | | 54 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | entropy | | | 10 | ++++++++++ |
A | funstats | | | 32 | ++++++++++++++++++++++++++++++++ |
3 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/badphrase b/badphrase
@@ -0,0 +1,54 @@
+#!/bin/sh
+# badphrase: creates a passphrase from a word dictionary
+
+# constants
+englishchars=26
+
+# flags
+charmin=6
+charmax=0
+copy=0
+entropymin=100
+includenames=0
+wordlist=/usr/share/dict/words
+wordnum=4
+
+usage() {
+ echo "usage: ${0##*/} [-ci] [-e entropymin] [-l wordlist] [-m charmax] \
+[-n charmin] [-w wordnum]" 1>&2
+ return 1;
+}
+
+while getopts ce:hil:m:n:w: arg; do
+ case $arg in
+ c) copy=1;;
+ e) entropymin=${OPTARG};;
+ h) usage;;
+ i) includenames=1;;
+ l) wordlist=${OPTARG};;
+ m) charmax=${OPTARG};;
+ n) charmin=${OPTARG};;
+ w) wordnum=${OPTARG};;
+ ?) usage;;
+ esac
+done
+shift $((OPTIND - 1))
+
+# password length should satisfy entropy requirements
+minlen=$(echo "l(2^${entropymin})/l($englishchars)" | bc -l)
+if [ "$(echo "${wordnum}*${charmin} >= ${minlen}" | bc -l)" -ne 1 ]; then
+ printf "%s: wordnum * charmin needs to be >= %.2f\n" "${0##*/}" "$minlen" 1>&2
+ exit 1;
+fi
+
+# generate the passphrase
+sort -R "$wordlist" | \
+if [ "$includenames" -eq 0 ]; then grep '^[^A-Z]'; else cat; fi | \
+if [ "$charmax" -lt "$charmin" ]; then grep -x ".\{${charmin},\}"; else grep -x ".\{${charmin},${charmax}\}"; fi | \
+head -n "$wordnum" | \
+# output the passphrase
+if [ "$copy" -eq 1 ]; then
+ paste -sd '' - | xclip -selection clipboard
+else
+ paste -sd ' ' -
+fi
diff --git a/entropy b/entropy
@@ -0,0 +1,10 @@
+#!/bin/sh
+# entropy: calculates the entropy of a password given the length and number of
+# possiblities
+
+num=0
+[ "$1" = '-n' ] && { num=1; shift; }
+[ "$#" -ne 2 ] && { echo "usage: ${0##*/} [-n] possibilites length " 1>&2; exit 1; }
+echo "l($1^$2)/l(2)" | bc -l | xargs printf "%.2f"
+[ "$num" -eq 0 ] && printf " bits of entropy"
+printf "\n"
diff --git a/funstats b/funstats
@@ -0,0 +1,32 @@
+#!/bin/sh
+# some cool stats for the tmux bar on openbsd
+
+vol () {
+ if [ "$(sndioctl -n output.mute)" -eq 1 ]; then
+ echo "muted"
+ else
+ sndioctl -n output.level | awk '{ printf "%d%%\n", int($0*100) }'
+ fi
+}
+
+mic () {
+ if [ "$(sysctl -n kern.audio.record)" -eq 1 ] || [ "$(sndioctl -n input.mute)" -eq 1 ]; then
+ printf "muted"
+ else
+ sndioctl -n input.level | awk '{ printf "%d%%\n", int($0*100) }'
+ fi
+}
+
+bat () {
+ apm -l
+}
+
+lidaction () {
+ [ "$(sysctl -n machdep.lidaction)" -eq 1 ] && printf "on" || printf "off"
+}
+
+temp () {
+ sysctl -n hw.sensors.cpu0.temp0 | awk '{ print $1, "C" }'
+}
+
+echo "|mic: $(mic)|vol: $(vol)|bat: $(bat)%|temp: $(temp)|lid: $(lidaction)|"