IsraelTorres

vigenere-ni.sh

Jun 22nd, 2012
93
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. :<<israeltorres_comment_block
  3.  
  4.  ./vigenere-ni.sh
  5.  Israel Torres
  6.  - 20120622
  7.  - non-interactive
  8.  - adapted from http://grulos.blogspot.com/2008/05/vigenre-cipher-in-pure-bash.html
  9.  
  10.  Mac OS X 10.7.4 11E53
  11.  Darwin Kernel Version 11.4.0
  12.  GNU bash, version 3.2.48(1)-release
  13.  
  14. israeltorres_comment_block
  15.  
  16. #required app check
  17. rqdapp='echo'
  18. hash $rqdapp 2>&- || { echo >&2 "$rqdapp binary not found - aborting"; exit 1; }
  19. #
  20.  
  21. if [ ! $# -lt 3 ]; then
  22.  
  23. a="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  24.  
  25. if [ $1 == "-d" ]; then
  26.     m=${1:+-}
  27. fi
  28.  
  29. t=$2; k=$3
  30.  
  31. for ((i=0;i<${#t};i++)); do
  32. p1=${a%%${t:$i:1}*}
  33. p2=${a%%${k:$((i%${#k})):1}*}
  34. d="${d}${a:$(((${#p1}${m:-+}${#p2})%${#a})):1}"
  35. done
  36. echo "$d"
  37.  
  38. else
  39.     echo "usage: $0 '-e STRING KEY'"
  40.     echo "usage: $0 '-d STRING KEY'"    
  41.     echo "example: $0 -e HELLO WORLD"
  42.     echo "example: $0 -e DSCWR WORLD"
  43. fi
  44. #eof
RAW Paste Data