Guest User

Untitled

a guest
Apr 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. Vigenère cipher in pure bash
  2. #!/usr/local/bin/bash
  3. # vigenere.sh
  4. # http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
  5.  
  6. a="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  7.  
  8. [[ "${*/-d/}" != "" ]] &&
  9. echo "Usage: $0 [-d]" && exit 1
  10. m=${1:+-}
  11.  
  12. printf "string: ";read t
  13. printf "keyphrase: ";read -s k
  14. printf "n"
  15. for ((i=0;i<${#t};i++)); do
  16. p1=${a%%${t:$i:1}*}
  17. p2=${a%%${k:$((i%${#k})):1}*}
  18. d="${d}${a:$(((${#p1}${m:-+}${#p2})%${#a})):1}"
  19. done
  20. echo "$d"
Add Comment
Please, Sign In to add comment