Skip to content

Instantly share code, notes, and snippets.

@seren
Created November 30, 2017 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seren/384ba1d453acbdb6f3dde811468ea3e5 to your computer and use it in GitHub Desktop.
Save seren/384ba1d453acbdb6f3dde811468ea3e5 to your computer and use it in GitHub Desktop.
obscure.sh
#!/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