Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- :<<israeltorres_comment_block
- ./vigenere-ni.sh
- Israel Torres
- - 20120622
- - non-interactive
- - adapted from http://grulos.blogspot.com/2008/05/vigenre-cipher-in-pure-bash.html
- Mac OS X 10.7.4 11E53
- Darwin Kernel Version 11.4.0
- GNU bash, version 3.2.48(1)-release
- israeltorres_comment_block
- #required app check
- rqdapp='echo'
- hash $rqdapp 2>&- || { echo >&2 "$rqdapp binary not found - aborting"; exit 1; }
- #
- if [ ! $# -lt 3 ]; then
- a="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- if [ $1 == "-d" ]; then
- m=${1:+-}
- fi
- t=$2; k=$3
- for ((i=0;i<${#t};i++)); do
- p1=${a%%${t:$i:1}*}
- p2=${a%%${k:$((i%${#k})):1}*}
- d="${d}${a:$(((${#p1}${m:-+}${#p2})%${#a})):1}"
- done
- echo "$d"
- else
- echo "usage: $0 '-e STRING KEY'"
- echo "usage: $0 '-d STRING KEY'"
- echo "example: $0 -e HELLO WORLD"
- echo "example: $0 -e DSCWR WORLD"
- fi
- #eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement