if [ "${BASH_SOURCE[0]}" == "${0}" ] then clear stty -echo echo 'Functions and descriptions: menu() Press Up and Down Arrows to move up and down Press Enter to select Paramerters: menu [title] [options] menu {string} {string...} Example: menu "Choose An Option:" "Option A" "Option B" "Option C" case $output in 1) functionA;; 2) functionB;; 3) functionC;; esac fullscreen() Asks user to fullscreen the terminal When they fullscreen, it continues the program Parameters: fullscreen fullscreen Example: fullscreen index() Gets the index of an item in an array named "array" Parameters: index [item] index {string} Example: array=("itemA" "itemB" "itemC") item=${array[$(($RANDOM % ${#array[@]}))]} index=$(index "$item") echo "Item ${index[0]} in the array is '\$item'" encode() Encodes a string with an integer passkey Can only encode lowercase letters Parameters: encode [message] [passkey] ["-string" or "-integer"] [custom cipher] encode {string} {integer or string} {flag} {array} Example: read plaintext read passkey encode "$plaintext" "$passkey" -string decode() Deocdes a string with an integer passkey Only decodes into lowercase letters Parameters: decode [encoded message] [passkey] ["-string" or "-integer"] [custom cipher] decode {string} {integer or string} {flag} {array} Example: read ciphertext read passkey decode "$ciphertext" "$passkey" -string' read stty echo fi menu() { clear printf "\e[1m$1\n" options=("${@:2}") chars=() for i in ${!options[@]} do option=${options[i]} new_option="" chars+=(${#option}) for (( n=0; n<${#option}; n++ )) do if [ "${option:n:1}" = "_" ] then new_option="$new_option " else new_option="$new_option${option:n:1}" fi done printf "\e[0m$new_option\n" done menu=1 while true do tput cup $menu ${chars[$((menu - 1))]} read -sn3 read case "$read" in $'\e[A') if [ $menu = 1 ] then menu=${#options[@]} else ((menu--)) fi ;; $'\e[B') if [ $menu = ${#options[@]} ] then menu=1 else ((menu++)) fi ;; "") output=$menu return esac done } fullscreen() { tput smcup while [ $(tput cols) -lt 200 ] && [ $(tput lines) -lt 60 ] do clear echo "Please fullscreen the terminal" echo "Status: Window" sleep 0.1 done clear echo "Status: Fullscreen" echo "Press enter to continue" stty -echo read stty echo } index() { index=() for i in ${!array[@]} do if [ "${array[$i]}" == "$1" ] then index+=($i) fi done echo ${index[@]} } encode() { if [ "$4" != "" ] then array=($4) else array=(- a b c d e f g h i j k l m n o p q r s t u v w x y z) fi cipher=() plain=$1 if [ "$3" == "-string" ] || [[ "$2" =~ [^0-9] ]] then key=0 for i in $(seq ${#2}) do index=$(index ${2:i-1:1}) if [ "${index[@]}" != "" ] then key=$(echo "$key+${index[0]}*${#array[@]}^($i-1)" | bc) fi done else key=$2 fi if [ "$3" == "-integer" ] && [[ "$2" =~ [^0-9] ]] then key=0 fi for i in $(seq ${#plain}) do if [ "${plain:$i-1:1}" == " " ] then index=0 else index=$(index ${plain:$i-1:1}) fi if [ "${index[@]}" == "" ] then cipher=(0 ${cipher[@]}) else cipher=($(echo ${index[0]}*$key | bc) ${cipher[@]}) fi done out="" i=0 while [ ${cipher[$i]} -gt 0 ] || [ $i -lt ${#plain} ] do ((i++)) mod=$(echo ${cipher[$i-1]}%${#array[@]} | bc) num=$(echo ${cipher[$i-1]}/${#array[@]} | bc) cipher[$i-1]=$mod cipher[$i]=$((${cipher[$i]}+$num)) letter=${cipher[$i-1]} out=${array[$letter]}$out done echo $out } decode() { if [ "$4" != "" ] then array=($4) else array=(- a b c d e f g h i j k l m n o p q r s t u v w x y z) fi plain=(0) cipher=$1 if [ "$3" == "-string" ] || [[ "$2" =~ [^0-9] ]] then key=0 for i in $(seq ${#2}) do index=$(index ${2:i-1:1}) if [ "${index[@]}" != "" ] then key=$(echo "$key+${index[0]}*${#array[@]}^($i-1)" | bc) fi done else key=$2 fi if [ "$3" == "-integer" ] && [[ "$2" =~ [^0-9] ]] then key=0 fi num=0 out="" for i in $(seq ${#cipher}) do if [ "${cipher:$i-1:1}" == " " ] then index=0 else index=$(index ${cipher:$i-1:1}) fi if [ "${index[@]}" == "" ] then plain+=(0) else plain+=(${index[0]}) fi index=$(($num*${#array[@]}+${plain[$i]})) num=$(($index%$key)) index=$(($index-$num)) index=$(($index/$key)) if [ $index -eq 0 ] then out+=" " else out+=${array[$index]} fi done if [ "${out:0:1}" == " " ] then echo ${out:1} else echo $out fi }