Want more features on Pastebin? Sign Up, it's FREE!
Guest

Keyfile Generator

By: a guest on Jul 22nd, 2013  |  syntax: Bash  |  size: 2.02 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2. #random random keyfile generator
  3.  
  4. ARGS=6
  5. E_BADARGS=85           
  6.  
  7.  
  8. if [ $# -ne "$ARGS" ]
  9. then
  10.         echo
  11.         echo "Usage: `basename $0` [keyfile_name] [extension] [amount] {bytes} {min-count} {max-count}"
  12. #       echo "Notice: [sudo apt-get install randomsound] before use"
  13.         echo "uses dd with /dev/urandom"
  14.         echo   
  15.         echo "Example: `basename $0` picture jpg 10 1024 512 4096"
  16.         echo "--will make directory named picture_10"
  17.         echo "--with 10 keyfiles named picture1.jpg to picture10.jpg"
  18.         echo "--keyfile size will be random between .52MB & 4.19MB"
  19.         echo   
  20.         exit $E_BADARGS
  21. fi
  22.  
  23. filename=$1
  24. extension=$2
  25. amount=$3
  26. bytes=$4
  27. count_min=$5
  28. count_max=$6
  29.  
  30.  
  31. echo
  32. #echo "Restarting entropy with randomsound (doesn't always have the best entropy from startup)"
  33. #sudo /etc/init.d/randomsound restart
  34.  
  35. mkdir "$filename"_"$amount"
  36.  
  37. maxsize=`echo "$bytes*$count_max*.000001" | bc`
  38. minsize=`echo "$bytes*$count_min*.000001" | bc`
  39. echo
  40. echo "MIN: $minsize""MB"" MAX: $maxsize""MB"
  41.  
  42. for a in `seq $amount`
  43. do
  44.         echo
  45.         entropy1=`cat /proc/sys/kernel/random/entropy_avail`
  46.         echo -n "Making $filename$a.$extension with entropy of:$entropy1"
  47.  
  48.         number=0
  49.         FLOOR=$count_min       
  50.         RANGE=$count_max
  51.        
  52.         #initialize random number range
  53.         while [ "$number" -le $FLOOR ]
  54.                 do
  55.                         SEED=$(head -1 /dev/urandom | od -N 1 | awk '{ print $2 }')
  56.                         RANDOM=$SEED
  57.                         number=$RANDOM 
  58.                         let "number %= $RANGE" # Scales $number down within $RANGE.
  59.                 done
  60.  
  61.         currentfilesize=`echo "$bytes*$number*.000001" | bc`    #helpful for large ones
  62.        
  63.         echo " will be $currentfilesize""MB"
  64.         echo "dd if=/dev/urandom of=./"$filename"_"$amount"/"$filename""$a"."$extension" bs=$bytes count=$number"
  65.        
  66.         dd if=/dev/urandom of=./"$filename"_"$amount"/"$filename""$a"."$extension" bs=$bytes count=$number
  67.        
  68.         entropy2=`cat /proc/sys/kernel/random/entropy_avail`
  69.         totale=`echo "$entropy1-$entropy2" | bc`
  70.        
  71. #       echo ".:: Pausing to generate more entropy ($totale used $entropy2 left) ::."
  72. #       sleep 3
  73.        
  74.         echo
  75. done
  76.  
  77. echo "Made $a keyfile(s) in /""$filename""_""$amount"
  78. echo
  79.  
  80. exit 0
clone this paste RAW Paste Data