From: Steven Baltakatei Sandoval Date: Sat, 23 Jan 2021 04:36:37 +0000 (+0000) Subject: style(unitproc/bknpass):Comment style X-Git-Tag: 0.4.0~6 X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/d46bdbc9a64294bb1c9256a09768d0065ac66bb3?hp=-c style(unitproc/bknpass):Comment style --- d46bdbc9a64294bb1c9256a09768d0065ac66bb3 diff --git a/unitproc/bknpass b/unitproc/bknpass index c9643ce..c1c1d1a 100755 --- a/unitproc/bknpass +++ b/unitproc/bknpass @@ -58,7 +58,7 @@ #==Initialization== -let ALPHABET_SIZE="32" # number of unique chars in bech32 base32 charset, argument fed to `tr -c` in 'Generate passphrase' step) +let ALPHABET_SIZE="32" # number of unique chars in bech32 base32 charset LOG_BASE=2 # Set logarithm base to 2 # Define `echoerr` function which outputs text to stderr @@ -67,7 +67,7 @@ function echoerr { echo "$@" 1>&2; } -# Define `rpass` function which generates a base32 passphrase of length $1 (ex: `rpass 22` generates a 22-char string) +# Define `rpass` function which generates a base32 passphrase of length $1 (ex: `rpass 20` generates a 20-char string) # Note: function adapted from https://www.thegeekstuff.com/2010/04/unix-bash-function-examples/ # Note: base32 charset uses bech32 charset function rpass { @@ -78,7 +78,7 @@ function rpass { #==Main Program== # Define $ENTROPY_BIT_COUNT1 as argument $1 or prompt user if $1 is not defined. - # note: argument test adapted from https://stackoverflow.com/a/6482403 +# Note: argument test adapted from https://stackoverflow.com/a/6482403 if [ -z "$1" ] then echo "Entropy bit count argument (\$1) not supplied." @@ -90,23 +90,24 @@ else fi # Check if $ENTROPY_BIT_COUNT1 is an non-negative integer - # Note: Regular expression test is adapted from https://stackoverflow.com/a/806923 +# Note: Regular expression test is adapted from https://stackoverflow.com/a/806923 RETEST1='^[0-9]+$' if ! [[ $ENTROPY_BIT_COUNT1 =~ $RETEST1 ]] ; then echo "error: Not an integer." >&2; exit 1 fi # Calculate minimum count of chars needed to encode $ENTROPY_BIT_COUNT1 with alphabet size of $ALPHABET_SIZE as float - # Solve ln(a^n)/ln(2)=b for n using `bc` where - # a=$ALPHABET_SIZE - # n=$CHAR_COUNT1_FLOAT - # b=$ENTROPY_BIT_COUNT1 - # Note: `bc` logarithm usage adapted from http://phodd.net/gnu-bc/bcfaq.html#bashlog +# Solve ln(a^n)/ln(2)=b for n using `bc` where +# a=$ALPHABET_SIZE +# n=$CHAR_COUNT1_FLOAT +# b=$ENTROPY_BIT_COUNT1 +# Note: `bc` logarithm usage adapted from http://phodd.net/gnu-bc/bcfaq.html#bashlog CHAR_COUNT1_FLOAT=$(echo "$ENTROPY_BIT_COUNT1*l($LOG_BASE)/l($ALPHABET_SIZE)" | bc -l) - # Note: Float will be of form "21.49744370650136860806". This particular float should be rounded to "22" later. +# Note: Float will be of form "21.49744370650136860806". +# Note: This particular example float should be rounded to "22" later. # Round $CHAR_COUNT1_FLOAT1 up to next highest integer for use as argument in later bash functions. - # Note: awk expression from https://bits.mdminhazulhaque.io/linux/round-number-in-bash-script.html +# Note: awk expression from https://bits.mdminhazulhaque.io/linux/round-number-in-bash-script.html CHAR_COUNT1=$(echo "$CHAR_COUNT1_FLOAT" | awk '{print ($0-int($0)>0)?int($0)+1:int($0)}') # Generate passphrase