IsraelTorres

alterotx.sh

Mar 5th, 2012
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # ./alterotx.sh
  3. # Israel Torres 20120305
  4. # alternate rotations
  5. # ./alterotx.sh '23' 'ISRAELTORRES'
  6. # ROLLX:    23
  7. # CRYPU:    LPUXHIWLUOHP
  8. # PLAIN:    ISRAELTORRES
  9. # CRYPD:    FVODBOQROUBV
  10. #
  11. # for i in {0..26}; do ./alterotx.sh $i 'ISRAELTORRES'; done
  12. #
  13. # Mac OS X 10.7.3 11D50b
  14. # Darwin Kernel Version 11.3.0
  15. # GNU bash, version 3.2.48(1)-release
  16. #
  17. # todo: add variables for inc/dec funcs
  18. function wrap_ascii (){
  19. MYASC=$1;ASCII_LOWER=65;ASCII_UPPER=90
  20. if [ "$1" -lt "$ASCII_LOWER" ]; then
  21. MYASC=$((ASCII_LOWER%$1))
  22. MYASC=$(($ASCII_UPPER-$MYASC+1))
  23. fi
  24. if [ "$1" -gt "$ASCII_UPPER" ]; then
  25. MYASC=$(($1%$ASCII_UPPER))
  26. MYASC=$(($ASCII_LOWER+$MYASC-1))
  27. fi
  28. echo $MYASC
  29. }
  30. function upme () {
  31. MYASC=$(printf '%d' "'${PLAIN:$i:1}'")
  32. MYCHR=$((MYASC+$ROLLX))
  33. MYNEW=$(wrap_ascii "$MYCHR")
  34. MYOUT=$(printf \\$(printf '%03o' $MYNEW))
  35. echo -n $MYOUT
  36. }
  37. function dnme () {
  38. MYASC=$(printf '%d' "'${PLAIN:$i:1}'")
  39. MYCHR=$((MYASC-$ROLLX))
  40. MYNEW=$(wrap_ascii "$MYCHR")
  41. MYOUT=$(printf \\$(printf '%03o' $MYNEW))
  42. echo -n $MYOUT
  43. }
  44. function roll_dn () {
  45. for (( i=0; i<$LEN_PLAIN; i++ )); do
  46. MYMOD=$(($i%2))
  47. if [ "$MYMOD" == 0 ]; then
  48. upme  
  49. fi
  50. if [ "$MYMOD" == 1 ]; then
  51. dnme
  52. fi
  53. done
  54. }
  55. function roll_up () {
  56. for (( i=0; i<$LEN_PLAIN; i++ )); do
  57. MYMOD=$(($i%2))
  58. if [ "$MYMOD" == 0 ]; then
  59. dnme  
  60. fi
  61. if [ "$MYMOD" == 1 ]; then
  62. upme
  63. fi
  64. done
  65. }
  66.  
  67. # main()
  68. if [ ! $# -lt 2 ]; then
  69.     PLAIN=$2; LEN_PLAIN=${#PLAIN}
  70.     ROLLX=$1
  71.     CRYPU=$(roll_up);CRYPD=$(roll_dn)
  72.     echo -e "ROLLX:\t$ROLLX"
  73.     echo -e "CRYPU:\t$CRYPU"
  74.     echo -e "PLAIN:\t$PLAIN"
  75.     echo -e "CRYPD:\t$CRYPD"
  76. else
  77.     echo "usage: $0 '#''STRING'"
  78.     echo "example: $0 '1' 'ISRAELTORRES'"
  79. fi
  80. #eof
RAW Paste Data