Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #!/bin/bash
  2. declare -a key # declare key as array
  3.  
  4. echo "Please key in four key"
  5.  
  6. read key[0,1,2,3]
  7.  
  8.  
  9.  
  10. i=0
  11.  
  12. for c in "${key[@]}"
  13.  
  14. do
  15.  
  16. lkey[$i]=${c,,}
  17.  
  18. i=$((${i} + 1))
  19.  
  20. done # translate all alphabet to lower character,lkey
  21.  
  22.  
  23.  
  24. function let2num {
  25.  
  26. for i in `echo "$1" | grep -o . ` ; do
  27.  
  28. echo $((`printf '%d' "'$i"` -97))
  29.  
  30. done
  31.  
  32. }
  33.  
  34. echo "What is your option"
  35.  
  36. echo "1) Encryption"
  37.  
  38. echo "2) Decryption"
  39.  
  40. echo "3) Exit"
  41.  
  42. read option;
  43.  
  44.  
  45.  
  46. if [ "$option" -eq "1" ]; then
  47.  
  48. echo "You selected Encryption"
  49.  
  50. elif [ "$option" -eq "2" ]; then
  51.  
  52. echo "You selected Decrypion"
  53.  
  54. elif [ "$option" -eq "3" ]; then
  55.  
  56. echo "You selected Exit,program will exit soon"
  57.  
  58. exit 0
  59.  
  60. else
  61.  
  62. echo "Invalid input,program will terminated soon"
  63.  
  64. exit 0
  65.  
  66. fi
  67.  
  68. echo "The key is ${lkey[@]}"
  69. echo `let2num ${lkey[@]}`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement