Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/sh
  2. #===================================================================================
  3. #
  4. #         FILE: HTS-Programming-01.sh
  5. #
  6. #        USAGE: HTS-Programming-01 scrambling_file
  7. #
  8. #  DESCRIPTION: This script is for level 1 challenge of HackThisSite
  9. #               programming missions.
  10. #  _____  _              _         _____  _                     _____     _____
  11. # |   __||_| _____  ___ | | ___   |  _  || | ___  ___    ___   |   __|   |  _  |
  12. # |__   || ||     || . || || -_|  |   __|| || .'||   |  |___|  |__   | _ |   __|_
  13. # |_____||_||_|_|_||  _||_||___|  |__|   |_||__,||_|_|         |_____||_||__|  |_|
  14. #                  |_|
  15. #
  16. #===================================================================================
  17.  
  18. # variable for final result
  19. unscrambling_word_list=""
  20.  
  21. # check file exists or not
  22. if [ -f $1 ] ; then
  23.  
  24.     # fetch scrambling words from file
  25.     scrambling_words=$(cat $1)
  26.  
  27.     # use grep and regular expression to find unscrambling words
  28.     for word in $scrambling_words ; do
  29.         regexp="^[$word]\+\{${#word}\}" #regexp
  30.  
  31.         testing="$(grep -e "$regexp" wordlist.txt | wc -l)"
  32.         if [ "$testing" == 1 ] ; then   # there's only one match, get it!
  33.             unscrambling_word_list="$unscrambling_word_list, $(grep -e "$regexp" wordlist.txt | tr -d '\r\n ')"
  34.         else                # multiple matches, need further checking
  35.         word_sorted="$(echo $word | grep -o . | sort -n | tr -d '\r\n ')"
  36.         # string comparison
  37.             for match in `grep -e "$regexp" wordlist.txt`
  38.             do
  39.         match_sorted="$(echo $match | grep -o . | sort -n | tr -d '\r\n ')"
  40.             if [ $word_sorted == $match_sorted ] ; then
  41.             unscrambling_word_list="$unscrambling_word_list, $(echo $match | tr -d '\r\n ')"
  42.         fi
  43.         done
  44.         fi
  45.     done
  46.     # display final result
  47.     echo $unscrambling_word_list
  48. fi
  49.  
  50. # bye bye
  51. exit 0