Created
November 30, 2017 20:49
-
-
Save seren/384ba1d453acbdb6f3dde811468ea3e5 to your computer and use it in GitHub Desktop.
obscure.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# obscure provides a command that will obscure any text passed in via standard input | |
# | |
# obscure replaces all the text passed into standard input, save the first five characters, | |
# with random symbols by default. It was developed as a way to show sensitive information | |
# (auth tokens, etc.) to the audience during presentations. It lets you prove, e.g., that | |
# an environment variable is set without disclosing the full contents of the variable. | |
# | |
# Example usage: $ echo $MYVAR | obscure | |
# | |
# Adapted from: https://github.com/paddycarver/obscure | |
obscure () { | |
type_of_mask=${MASK_TYPE:-random} | |
num_chars_to_show=${SHOW_CHARS:-5} | |
IFS= read -r str | |
(( num_chars_to_mask = ${#str} - ${num_chars_to_show} )) | |
echo -n "${str:0:${num_chars_to_show}}" | |
case "$type_of_mask" in | |
snip) | |
echo '<snip>' | |
;; | |
xxx) | |
for (( i = 0 ; i < ${num_chars_to_mask} ; i++ )); do | |
echo -n 'x' | |
done | |
;; | |
*) | |
echo -n "$(cat /dev/urandom | LC_CTYPE=C tr -cd "[:graph:]" | head -c ${1:-${num_chars_to_mask}})" | |
;; | |
esac | |
echo | |
} | |
obscure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment