From: Steven Baltakatei Sandoval Date: Sat, 23 Jan 2021 03:48:22 +0000 (+0000) Subject: feat(unitproc:bknpass):Change bknpass to use bech32 base32 charset X-Git-Tag: 0.4.0~7 X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/8fd9a3cb61c84b763d64722ecf4472dafcb2f05e?ds=inline;hp=9c8765b4d681d1e705d7cec2d64bbf61ea98efff feat(unitproc:bknpass):Change bknpass to use bech32 base32 charset --- diff --git a/unitproc/bknpass b/unitproc/bknpass index 4f53da0..c9643ce 100755 --- a/unitproc/bknpass +++ b/unitproc/bknpass @@ -1,14 +1,12 @@ #!/bin/bash -# Date: 2020-01-20T16:34Z -# # Author: Steven Baltakatei Sandoval (baltakatei.com) # # License: This bash script, `bknpass`, is licensed under GPLv3 or # later by Steven Baltakatei Sandoval: # # `bknpass`, an alphanumeric password generator -# Copyright (C) 2020 Steven Baltakatei Sandoval (baltakatei.com) +# Copyright (C) 2021 Steven Baltakatei Sandoval (baltakatei.com) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -34,8 +32,8 @@ # - Check if user-provided string is an integer using `bash` regular # expression test. # -# - Calculate the minimum number of alphanumeric characters required -# to encode the specified number of bits of entropy. +# - Calculate the minimum number of bech32 base32 characters +# required to encode the specified number of bits of entropy. # # - This step uses `bc` to calculate a logarithm float string # and `awk` to convert the float into an integer, rounding up. @@ -47,6 +45,10 @@ # - Use `echo` to display the passphrase in stdout with a trailing # newline. # +# Usage: bknpass [int] +# +# Example: bknpass 256 +# # Dependencies: bash, echo, bc, awk, tr, head. See end of file # # Tested on: @@ -56,7 +58,7 @@ #==Initialization== -let ALPHABET_SIZE="26+26+10" # number of unique chars in [:alnum:], argument fed to `tr -c` in 'Generate passphrase' step) +let ALPHABET_SIZE="32" # number of unique chars in bech32 base32 charset, argument fed to `tr -c` in 'Generate passphrase' step) LOG_BASE=2 # Set logarithm base to 2 # Define `echoerr` function which outputs text to stderr @@ -65,10 +67,11 @@ function echoerr { echo "$@" 1>&2; } -# Define `rpass` function which generates an alphanumeric passphrase of length $1 (ex: `rpass 22` generates a 22-char string) - # Note: function adapted from https://www.thegeekstuff.com/2010/04/unix-bash-function-examples/ +# Define `rpass` function which generates a base32 passphrase of length $1 (ex: `rpass 22` generates a 22-char string) +# Note: function adapted from https://www.thegeekstuff.com/2010/04/unix-bash-function-examples/ +# Note: base32 charset uses bech32 charset function rpass { - cat /dev/urandom | LC_ALL=C tr -cd "[:alnum:]" | head -c ${1:-22} + cat /dev/urandom | LC_ALL=C tr -cd "qpzry9x8gf2tvdw0s3jn54khce6mua7l" | head -c ${1:-22} } @@ -148,6 +151,13 @@ echo -e "$PASS1" # Date: 2010-04-21 # Date Accessed: 2020-01-20 # +# - Bech32 base32 charset +# https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki +# Author: Pieter Wuille +# Date: 2017-03-20 +# License: BSD-2-Clause +# Date: Accessed: 2021-01-23 +# # - Dependencies: bash, echo, bc, awk, tr, head. # # - GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)