Advertisement
howtophil

Store encrypted file as PNG (2017/01/15)

Jan 15th, 2017
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.70 KB | None | 0 0
  1. #!/bin/bash
  2. #------------------------------------------------------------
  3. # To encrypt and store a file as a lossless PNG
  4. #
  5. # $ cat fileto.store | ./tocolor.sh imagefilename.png columnsize
  6. #
  7. # You will be prompted for your encryption key/passphrase
  8. #
  9. # You can pipe pretty much anything into it
  10. # so output from tar, echo, etc will all work too.
  11. #------------------------------------------------------------
  12.  
  13. #-----------------------------------------
  14. # Initialize some counters
  15. #-----------------------------------------
  16. counter=0
  17. rowcounter=0
  18. colorcounter=0
  19.  
  20. #-----------------------------------------
  21. # Initialize color arrays
  22. # and cache some math to make things
  23. # run faster.
  24. #-----------------------------------------
  25. declare -A colorarray
  26. declare -A fabcolors
  27. alphaarray=(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)
  28.  
  29. # Blues and purples theme
  30. precolorarray=(000080 00008B 0000CD 0000FF 191970 1E90FF 4169E1 483D8B 4B0081 4B0182 6A5ACD 7B68EE 800080 8A2BE1 8A2CE2 8B008B 9370DB 9400D3 9932CC BA55D3 D8BFD8 DA70D6 DDA0DD E6E6FA EE82EE FF11FF FF00FF)
  31.  
  32. # Or dark greys to look black instead
  33. # precolorarray=(000001 000002 000003 000004 000005 000006 000007 000008 000009 000010 000011 000012 000013 000014 000015 000016 000017 000018 000019 000020 000021 000022 000023 000024 000025 000026)
  34.  
  35. for oneletter in "${alphaarray[@]}"
  36. do
  37.     # Fill the colorarray
  38.     colorarray["$oneletter"]="${precolorarray[$colorcounter]}"
  39.     let colorcounter+=1
  40.  
  41.     # Fill the fabcolors array
  42.     hexinput=${colorarray[$oneletter]}
  43.     a=`echo $hexinput | cut -c-2`
  44.     b=`echo $hexinput | cut -c3-4`
  45.     c=`echo $hexinput | cut -c5-6`
  46.     r=`echo "ibase=16; $a" | bc`
  47.     g=`echo "ibase=16; $b" | bc`
  48.     b=`echo "ibase=16; $c" | bc`
  49.     fabcolors[$oneletter]="(  $r,  $g,  $b)  #$hexinput  srgb($r,$g,$b)\n"
  50.  
  51. done
  52.  
  53. #-----------------------------------------
  54. # How wide did we set the image?
  55. # or just default to 500 pixels wide
  56. #-----------------------------------------
  57.  
  58. if [ ! -n "$2" ]; then
  59.     echo "Setting Column Size to 500"
  60.     columnsize=500
  61. else
  62.     echo "Setting Column Size to $2"
  63.     columnsize=$2
  64. fi
  65. collimit=$(($columnsize-1))
  66.  
  67. #-----------------------------------------
  68. # start encrypting, encoding, and
  69. # building the PNG.
  70. #-----------------------------------------
  71. ccrypt -e | codegroup | tr '\n' ' '| (
  72.     # while loop
  73.     while IFS= read -r -n1 theletter
  74.     do
  75.         if [ $counter -gt $collimit ]; then
  76.             counter=0
  77.             let rowcounter+=1
  78.         fi
  79.         if [[ $theletter = *[!\ ]* ]]; then
  80.             echo -e -n "$counter,$rowcounter: ${fabcolors[$theletter]}"
  81.             let counter+=1
  82.         fi
  83.     done
  84.     let rowcounter+=1
  85.     echo " ImageMagick pixel enumeration: $columnsize,$rowcounter,255,srgb"
  86. ) |sed '1h;1d;$!H;$!d;G' | convert -monitor txt: "$1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement